Reputation:
Lets suppose activities(A,B,C) are opened in following sequence:
A -> B -> A -> C-> A
Now in normal case the activity backstack will look
| A |
| C |
| A |
| B |
| A |
Is there any way I can make sure that Activity A
resides in the backstack only once? Or in other words backstack look like:
| A |
| C |
| B |
EDIT : I want that new instance of activity is launched every time, and all previous instances are removed from stack. Is it even possible using built in schemes?
Upvotes: 1
Views: 912
Reputation: 53657
You need to set android:launchMode="singleTask"
or android:launchMode="singleInstance"
for each activity in manifest.
Upvotes: 2
Reputation: 1359
If you want A to still be at the beginning then it sounds like you want to launch B and C as activities for results. See Activity.startActivityForResult
That way, the original activity A will launch B and C and when B and C exit they will return to the original A.
Otherwise, If you want A to go to the top NickT has the right answer.
Upvotes: 0
Reputation: 7924
android:launchMode in your manifest may help:
http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
It's kind of geared to the main activity of your application though, not to arbitrary activities in your stack.
Edit: see NickT's answer, which i have upvoted :)
Upvotes: 0
Reputation: 23873
It sounds like you want to make use of the intent flag FLAG_ACTIVITY_REORDER_TO_FRONT
Upvotes: 4