Reputation: 55
I have some problem with my application, I have 4 buttons, one to start each of the other activities. Say activity is called a,b,c,d. I want to be able to change between this activities without getting 100ds of paused activities in the stack but still save the back history.
I.e a->b->a->c->d->a where all a is the same instance of the activity
So practically what I want is to be able to restart the very same instance of the activity instead of starting a new one.
Possible?
Upvotes: 1
Views: 2008
Reputation: 4354
If your activity "a" is your home, you can add these flags:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Then, when you press back, the application will exit (because you cleared all others activities) => doc
Upvotes: 0
Reputation: 42016
Yes, It is possible.
mIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
mIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Add this flag to your intents, this will bring your activity on top of stack rather than creating new one.
Upvotes: 6