Activity with Flag FLAG_ACTIVITY_CLEAR_TOP (android)

后端 未结 2 874
醉梦人生
醉梦人生 2021-01-12 22:12

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

相关标签:
2条回答
  • 2021-01-12 22:35

    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.

    0 讨论(0)
  • 2021-01-12 22:48

    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].

    0 讨论(0)
提交回复
热议问题