The default animation when the Back
button is pressed is a slide from left to right. I'd like to replace that with a custom animation. I'm currently thinking that some combination of onBackPressed()
and overridePendingTransition
will do the trick, but I haven't been able to get it working.
I think you shouldn't use finish() because the data stored by the Views will be erased
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
}
Figured it out. I wasn't finshing the current activity. The following code does the trick.
@Override
public void onBackPressed() {
[This Activity].this.finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
if you want no animation
follow the code in Activity
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(0,0);
}
Reference : https://developer.android.com/reference/android/app/Activity.html#overridePendingTransition(int, int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With