overridePendingTransition does not work when FLAG_ACTIVITY_REORDER_TO_FRONT is used
Solution 1
Actually the right solution when using REORDER_TO_FRONT is to call overridePendingTransition in the method onNewIntent() of the activity you are going to open.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
replace with your transitions.
If you need to selectively replace the transition you can add an extra in your intent and check it in the onNewIntent() to decide what to do.
This is not suitable if you don't know the transition that will be opened (if you don't specify it explicitly for example) but otherwise is the right solution.
Solution 2
I ran into this same problem. The trick is to override the transition in the onResume() callback.
@Override
public void onResume() {
super.onResume();
overridePendingTransition(R.anim.transition_to_right, R.anim.transition_to_left);
}
Solution 3
for me, the solution was to make sure it's ran in the UI thread
runOnUiThread(new Runnable() {
public void run() {
startActivity(new Intent(ActivityOne.this, ActivityTwo.class));
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
});
finish();
Solution 4
I got the same problem. I suggest you check your AndroidManifest.xml to make sure ActivityA and ActivityB both have no set Theme.Translucent.NoTitleBar, this theme contains "android:windowIsTranslucent"=true cause the issue.
Hope this help you.
Solution 5
Calling
overridePendingTransition(R.anim.transition_to_right, R.anim.transition_to_left);
after finish(); of the closing activity worked for me.
finish();
overridePendingTransition(R.anim.transition_to_right, R.anim.transition_to_left);
It's better than calling onResume, because it makes the activity more independent about the enter and exit animations:
Calling after finish of sender activity:
Activity A ---Enter Transition 1 (on A)---> Activity B ---Enter Transition 2 (on B)---> Activity C
Activity A <---Exit Transition 1 (on B)--- Activity B <---Exit Transition 2 (on C)--- Activity C
Activity A ---Enter Transition 1 (on A)---> Activity C ---Enter Transition 3 (on C)---> Activity B
Activity A <---Exit Transition 3 (on C)--- Activity C <---Exit Transition 2 (on B)--- Activity B
Calling on onResume of receiver activity:
Activity A ---Enter Transition 1 (on B)---> Activity B ---Enter Transition 2 (on C)---> Activity C
Activity A <---Enter Transition 1 (on A)--- Activity B <---Enter Transition 2 (on B)--- Activity C
Activity A ---Enter Transition 3 (on C)---> Activity C ---Enter Transition 2 (on B)---> Activity B
Activity A <---Enter Transition 1 (on A)--- Activity C <---Enter Transition 3 (on C)--- Activity B
Here the onResume animation always have to be the same no matter which sender activity it is, instead the first approach, where you can custom the animation easily.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on August 13, 2020Comments
-
Admin almost 4 years
I have two activities in the stack, in order to show them I use FLAG_ACTIVITY_REORDER_TO_FRONT. So far so good, the problem comes when I want to bring the activity with an animation using overridePendingTransition.
Intent i = new Intent(ActivityA.this, ActivityB.class); i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); ActivityA.this.startActivity(i); overridePendingTransition(R.anim.transition_to_right, R.anim.transition_to_left);
The transition is not shown, however, if the flag is not added to the intent (removing line 2) then there is no problem.
Is it possible to bring an activity to front with an animation?
Thanks a lot!
-
Admin over 13 yearsHmm...sounds like a good idea! thanks a lot. Im going to learn how to deal with animations and try that.
-
GSree over 13 years@Daniel check out APIDemos (provided along with android framework) com.example.android.apis.animation.Rotation3dAnimation.java and how it is used in Transition3D.java. Should give you good insight.
-
Admin over 13 yearsThanks GSree for your help! I have tried to launch a slide-out animation in the onPause() from activity A, and a slide-in in the onResume() from activity B. It was a nice idea, and it work out, but it is not smooth enough, as you can see a kind of black blink, because the animations are not excuted at the same time. I keep working on this, if I find a good solution I will let it know.
-
GSree over 13 yearsGood to know that. Let me know how it goes
-
Ravi about 11 yearsby doing it in onResume(). The effect is not at all smooth when the first activity is brought on top , it appears with a jerk
-
cwhsu over 10 yearsthis works for me when I start a new activity from service, and need to override pending transaition!
-
Daniele Segato almost 10 yearsThis suggestion is not correct. onResume is called in many occasion that have nothing to do with a new intent being used. The correct solution is the one I pointed out: do it in onNewIntent() method
-
tomrozb almost 10 yearsThe only proper solution. Should be accepted answer.
-
Daniele Segato almost 10 yearsWhy would you do that when onNewIntent() method has been created just for that reason? onCreate(), onStart(), and onResume() serve completely different purposes
-
Daniele Segato over 9 yearsI wish I know why some people downvoted my answer, this is, as tomrozb said, the only proper solution
-
M Penades about 9 yearsin my case, that was exactly my mistake
-
androidguy about 6 yearsOriginal question didn't state the original activity is being finished. This answer isn't relevant if you're starting one without finishing,
-
androidguy about 6 yearsSince
onNewIntent
isn't called when the activity is created, you'll have to also dooverridePendingTransition
where you start the activity. -
Daniele Segato about 6 yearsThat i obvious :-) i never said you need to do it in only one place. And by the way: now navigation Controller should be used
-
Oyeme about 5 yearsI spent hours looking for a solution. Cheers
-
seekingStillness about 4 yearsDoes
onNewIntent
get called on the first load of the Activity? If not, then the animation won't show on the first load. -
Daniele Segato about 4 years@seekingStillness no it does not,
onNewIntent()
is only for when you re-open an activity with a new intent. For the fist time you can do ononCreate()
only ifsavedInstanceState
isnull
(be sure to usesaveInstanceState()
so that it will not benull
after the first time)