Reputation: 789
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?
Upvotes: 0
Views: 1045
Reputation: 566
Think that all the activities are saved in a Stack, for example if you put the main activity and then you call a secondeone, when you finish that second activity the main will be put in the front. So if you know where is the activity, yes, you could re-use it ;)
hope to be usefull :)
Upvotes: 1
Reputation: 11782
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_FRONT
in your Intent to reshuffle your activity to the front.
Alternately, you can also use FLAG_ACTIVITY_CLEAR_TOP
to clear the stack on top of your activity.
Upvotes: 1