'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 i.e. 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?
Solution 1:[1]
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();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Wasser |
