ScottishUser ScottishUser - 1 year ago 140
Android Question

Delete old activity instance when starting a new activity

I'm looking to delete/remove an old activity instance when a new instance (of same activity) is created, however I need to maintain all other activities in back-stack (therefore FLAG_ACTIVITY_CLEAR_TOP won't suffice).

E.g. say I have activities A, B & C.
I start: A -> B -> C -> B.
On the start of the second B activity I need to remove the existing B activity.
Therefore I now have: A -> C -> B running...

Any help appreciated.

Answer Source

It seems that deleting the activity is not as easy as I would have imagined therefore not a complete answer but I'm going to go with using FLAG_ACTIVITY_REORDER_TO_FRONT. This will not kill the existing activity but instead move it to top of stack.

Intent intent = new Intent(ctx, Activity.class);

This will allow for the activity navigation outlined above.

I'm still interested if someone knows of a means to clear the actual activity.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download