Is there a way to programmaticaly see if an activity already exists in the stack and re-use it instead of re-creating it?
The situation occurs that a user can enter an activity via multiple routes and go onward via multiple routes also. However that same activity can be reached again after a few more clicks through other activities. I want to avoid the app going the creation of a new activity when I know it already exists in the stack.
This might just be down to my bad design (this is my first app). But was just wondering how this can be managed? Is there a solution to this?
Well this kind of freeform activity access is a bit frowned on in the android UI guidelines, but you can use the
FLAG_ACTIVITY_REORDER_TO_FRONTin your Intent to reshuffle your activity to the front.Alternately, you can also use
FLAG_ACTIVITY_CLEAR_TOPto clear the stack on top of your activity.