Activity with flag FLAG_ACTIVITY_CLEAR_TOP (android)

I have a stack of actions launched one after another.
but in one of the actions I need to run this particular view with the flag FLAG_ACTIVITY_CLEAR_TOP.

To complete all previous steps and start.

Problem. I am faced with the fact that I do not want to finish one of the actions from the stack, it should be the presence on the back of the newly launched action.

Suppose I have actions. [A] [B] [C] [D]
I start an [D]activity with a flag FLAG_ACTIVITY_CLEAR_TOPafter starting an activity [D], it destroys all the actions, I want the activity [B]to continue working on the back side and when we press the key [D], it should display the activity [B].

How to do it?

Thanks,
PP.

+5
source share
2 answers

As @Mudassir said, start the action [A]. When you call [B], just use FLAG to clear all the data, but [B], and then you can call [D] without the flag from [B], having [B] [D], how would you like? Then press the back button to go from [D] to [B], without any other data ?. It doesn't seem like you think he wants you to call [B] the flag from [D], and what would be the purpose of this? At this point, you will end with just [B].

- In any case, you lose [C] along the way. The solution may be:

startActivity(A)
[in activity A] startActivity(B) - WITH CLEAR_TOP TO KILL [A]
[in activity B] startActivityForResult(C) - WHEN [C] IS finish() IT WILL COME BACK TO [B]
[in activity B, onActivityResult()] startActivity(D)

This will give you JUST [B] and [D], while it still comes to [C] .... try, it will work.

+3
source

Activity [B] FLAG_ACTIVITY_CLEAR_TOP, , [B]. Activity [D].

+5

All Articles