简体   繁体   中英

How do you track if an activity is re-called from backstack?

So I am trying to implement animations. Please assume that all the animations here is working as I have checked them one by one.

When an activity is new : Enter : Slide in From Right Exit : Slide out to Left

What I want to do now is, when user presses the back button the current activity will Slide Out to Right and the activity that is called from backstack will Slide In From Left

I've overridden the onBackPressed method and here is the code :

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(0, R.anim.slide_out_to_right);
}

I tried the onRestart method in the AppCompatActivity and overridePendingTransitions but it is not working.

@Override
protected void onRestart() {
    super.onRestart();
    overridePendingTransition(R.anim.slide_in_from_left, 0);
}

The animation of the activity called from backstack is still Slide In From Right which should be Slide In From Left . Any ideas how I can fix this?

I believe what you need is onStart() since it is always called no matter what.

OnResume() might not be called at all or possibly it is called to early in the process.

Please check my friend's session for additional information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM