How can I add an animation to the activity finish()
I'm using overridePendingTransition for when my activity is created and that works fine I can see the fade in works great, but when I try and animate the finish on the activity it is still doing the default right to left slide.
I first tried defining the out animation when I start the activity as follows:
Intent myIntent = new Intent(a, SkdyAlert.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
a.startActivity(myIntent);
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
AnimationHelper.overridePendingTransition(a, R.anim.fadein, R.anim.fadeout);
}
Then I tried doing it when I finish the activity as well
okBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
AnimationHelper.overridePendingTransition(activity, 0, R.anim.fadeout);
}
}
});
But neither of these approaches will prevent the "right to left" slide for the exit animation. Any ideas on what I'm doing wrong?
I override pending transition just after calling finish();
In my case, I have done it to avoid transitions.
finish();
Details.this.overridePendingTransition(R.anim.nothing,R.anim.nothing);
Order is important :)
This question has already answered but the most efficient way to put an animation while exiting from an activity is by overriding the "finish()" method of the related activity:
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.hold, R.anim.slide_out_bottom);
}