Search code examples
androidandroid-activity

Android Activity remove from stack


I want to completely remove an Activity from the Task Stack, but finish() only seems to minimize the Task. If I click on the button on my phone that browses all the open Tasks, it's still there. I would need to swipe it away to get rid of it.

How do I actually get rid of an Activity completely? Currently I have Activity_A that launches Activity_B. When I press back, Activity_B minimizes and Activity_A is brought to the front. How do I make it simply get rid of Activity_B and return to Activity_A?

EDIT:

I found the reason, Activity_B had Activity_A as the parent callback Activity. If you do not launch a new activity when A calls B, then it works properly (killing B kills the whole thing, A doesn't resurface).


Solution

  • What I ended up doing was that when Activity_A calls up Activity_B, it doesn't create a new Activity but instead just replaces it. So then when I get rid of B (by swiping it away, for example), it doesn't go back to A.

    Otherwise, B will have a callback to A then basically brings A back to the front when you get rid of B.