Activity with Flag FLAG_ACTIVITY_CLEAR_TOP (android)
I have stack of activities launched after one another.
but in one of the activity I need to launch that particular activity with flagFLAG_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 th开发者_StackOverflow社区e stack it should be presence on back of the newly launched activity.
Suppose I have activities [A] [B] [C] [D]
[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.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]
.
Like @Mudassir said, start activity [A]. When you call [B] simply use the FLAG to clear all data but [B], and then you can call [D] without flag from [B];thus having [B][D] like you wanted? Then on back button press you will go from [D] to [B], without having any other data?. You seem to not be thinking he wants you to call [B] with flag from [D], and what would the purpose of that be? You'd wind up with just [B] at that point.
-Either way, you lose [C] along the way. A solution might 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]&[D] while still getting to [C]....try it, it will work.
精彩评论