Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overridePendingTransition does not work when FLAG_ACTIVITY_REORDER_TO_FRONT is used

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!

like image 599
Daniel Avatar asked Jan 08 '11 11:01

Daniel


3 Answers

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.

like image 112
Daniele Segato Avatar answered Nov 08 '22 12:11

Daniele Segato


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);
}
like image 35
bradley4 Avatar answered Nov 08 '22 14:11

bradley4


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();
like image 5
K-RAD Avatar answered Nov 08 '22 12:11

K-RAD