I have stack of activities launched after one another.
but in one of the activity I need to launch that particular activity with flag FLAG_ACTIVITY_CLEAR_TOP
.
So that it will finish all the previous activities and start.
Problem I am facing that i don't want to finish one of the activity from the stack it should be presence on back of the newly launched activity.
Suppose I have activities [A] [B] [C] [D]
I am starting [D]
activity with flag FLAG_ACTIVITY_CLEAR_TOP
after starting activity [D]
it will destroy all the activities, I want activity [B]
to be kept running on the back and when we press back key on [D]
it should display activity [B]
.
How to do this?
Thanks,
PP.
Flag Activity Clear Top destroys target activity and than creating it. Android, what Intent flags are recommended for Activities started by Notifications.
A flag is a setting that allows the configuration of or gating of some logic or feature. It can almost be thought of as a simple constant but with some extra functionality that we will go over in this document.
Use addFlags() so that you can add multiple number of Flags to Intent.
The flags you can use to modify the default behavior are: FLAG_ACTIVITY_NEW_TASK. Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent() .
One solution is to call Activity [B]
with flag FLAG_ACTIVITY_CLEAR_TOP
, this will destroy all activities but [B]
. After that, call Activity [D]
.
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