简体   繁体   中英

Restart a new instance of an activity already in the stack

I have a home activity A, from where I open activity B. In B there are some complex views with states with data fetched from the.network. From B with the press of a button I go to activity C.
Now if I press back, I go to B with the states preserved.
Problem: I want to have a button in C and when I press it I open B but in a fresh state ie like it was called for the first time but the back button functionality to not break. I also want to keep activity A on the stack as the flow was.
How can I do this?

To return from C to B but create a new instance of B, do this in C:

Intent intent = new Intent(this, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();

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