Reputation: 73
Back Button Navigation problem: when pressing Back button while the activity is getting animated, if the back button is pressed, it will to navigate to previous activity twice. How to resolve it?
This is our Code
final Intent intent = new Intent(getApplicationContext(), DrugHelp.class);
ActivitySwitcher.animationOut(findViewById(R.id.container),getWindowManager(),
new AnimationFinishedListener() {
@Override
public void onAnimationFinished() {
startActivity(intent);
finish();
}});
Upvotes: 0
Views: 588
Reputation: 1168
if it is just previous activity you are launching in side onAnimationFinished
, then don't call startActivity, just finish the current activity only
Upvotes: 0
Reputation: 44571
I assume DrugHelp
was the Activity
previous to this one. It was probably never finished so it is still on the stack. If this is the case, simply finishing this Activivty
will take you to the previous one that hasn't been finished. You can also use Intent Flags
to bring that one to the front of the stack if it already exists.
final Intent intent = new Intent(getApplicationContext(), DrugHelp.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
You also could use Intent.FLAG_ACTIVITY_CLEAR_TOP
if you want to make sure that all other Activities
on the stack are taken off.
Upvotes: 1
Reputation: 3373
Try this:
public void onBackPressed() {
this.finish();
}
If it still go back twice, set a boolean to true when you're starting your animation, and in the function above, add
if(!yourBoolean){
this.finish();
}
Hope this help.
Upvotes: 1