In our app, we have Activities A,B,C,D, and E. The user usually goes from A to E, moving through B,C,D.
In Activity E we want to go back to A, and get rid of B,C,D from the stack. We don't want to recreate A from E.
How do I 'pop off' B,C,D from the stack and then return to A?
Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.
A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.
The back button (by default) then 'pops' the stack, calling finish() on the topmost activity, destroying it and removing it from the back stack and taking you back to the previous activity.
If A is already running, you can use the FLAG_ACTIVITY_CLEAR_TOP flag when starting an intent to go back to A.
See also, similar questions:
How to clear current activities in the stack?
how to kill sub activities and bring activity to top of stack
Use the android:noHistory property in the manifest:
http://developer.android.com/guide/topics/manifest/activity-element.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With