简体   繁体   中英

how to start A activity after finish old A activity

I tried to set intent.setFlags (FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_NEW_TASK) , but the effect is not as I think.

It will execute onResume () in the old A activity.

But I want the effect as shown below:

A activity onCreate() ... onPause()

anywhere(from notification, from B activity ...) start A activity again

old A activity onDestory()

create new A activity

use (FLAG_ACTIVITY_CLEAR_TOP) flag when u passing intent. then after startactivity() use finish() method.

you should use FLAG_ACTIVITY_CLEAR_TOP

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

SAMPLE CODE

Intent i = new Intent(YourActivity.this, OTHERACTIVITY.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

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