0

I'm making a notes app and I'm trying to use overridePendingTransition(); to add transition between activities and I'm running into an issue. The effect I'm going for is when I add a new note the new activity comes in from the bottom which I have working. Now when I try to go back to my other activity I want the note to exit to the bottom, which it does but the activity switches and when it exits the activity behind is still the same activity until it's off screen then it switches. I'm going to include a link to show what I mean since this sounds very confusing. Any help would be greatly appreciated. Thanks everyone :)

https://youtu.be/Pw5HRwgsrok

this is the anim xml im using

trans_infrom_bottom.xml

<?xml version="1.0" encoding="utf-8"?>

<translate
    android:fromYDelta="100%"
    android:toYDelta="0%"
    android:duration="275"/>

trans_outto_bottom.xml

<?xml version="1.0" encoding="utf-8"?>

<translate
    android:fromYDelta="0%"
    android:toYDelta="100%"
    android:duration="275"/>

trans_notrans.xml

<?xml version="1.0" encoding="utf-8"?>

<translate
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:duration="275"/>

MainActivity.java

public void Add_New_Note(View view) {
    Intent new_note = new Intent(this, New_Note.class);
    startActivity(new_note);
    overridePendingTransition(R.anim.trans_infrom_bottom, R.anim.trans_notrans);
}

New_Note.java

public void back_to_sheets(View view) {

    Intent back_to_sheets = new Intent(this, MainActivity.class);
    startActivity(back_to_sheets);
    overridePendingTransition(R.anim.trans_outto_bottom, R.anim.trans_notrans);
}
Shadow Suave
  • 114
  • 1
  • 10
  • Show your java code. Remember, you must call overridePendingTransition() exactly after finish() or startActivity() – bukkojot Sep 21 '17 at 14:39
  • Okay, I added the java code. I apologize for my ignorance btw, i am VERY new to java and android development lol, i just bought a book to learn but im kind of jumping ahead and trying to learn a little bit on my own and with online help and i figured a notes app is pretty basic to start with lol. also thank you for your help :) – Shadow Suave Sep 21 '17 at 19:43

3 Answers3

0

Try to override behavior of back button:

@Override
public void onBackPressed() {
    finish();
    overridePendingTransition(R.anim.trans_outto_bottom, R.anim.trans_outto_left);
}

It will add animation on pressing back button

bukkojot
  • 1,526
  • 1
  • 11
  • 16
  • Is that the only way to get the effect I want? I want it to exit to the bottom when I press the back arrow in the app, not the back button on the phone. I'm just trying to get the effect that as the current activity slides off to the bottom the previous activity appears underneath it. Kind of how the new note comes in, but comeplete opposite – Shadow Suave Sep 22 '17 at 02:54
0

You should consider use fragment instead Activity for make simple code, and maybe can reuse the same fragment with multiple instances for make multiple notes.

Answer your question as @bukkojot propose you need implement finish() method not start the activity again, because that activity is already in the backStack. So the only way to go back is that activity.

You can check this other answer to see how handle backButton on Toolbar How to implement android Toolbar Back button.

K. Jorge
  • 53
  • 7
0

use this library SwipeBack is an android library that can finish a activity by using gesture.

Hardik Mehta
  • 867
  • 1
  • 12
  • 20