androidactivity-stack

How to clear current activity stack when start another activity which belong to another stack


For example:A start B, B start C, A and C belongs to 'Hello'-stack, and B belongs to 'World'-stack, when user press back button in Activity C, it will return to A. Note1:B means a lot of activities , not just one activity, like A start B1,B1 start B2, B2 start B3....,Bn start C. Note2:I need Bs remain in stack until C has been launched , when user press back in B3, it should return to b2. enter image description here

I actually have implemented this need by using startActivityForResult,and I just want to know is there any way using stack to implements this.


Solution

  • intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); or intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); works for me.