Reputation: 9823
Let's say I have Activity A and Activity B.
In A, I have a button which when clicked runs the following code
startActivity(new Intent(this, ActivityB.class));
In B, I have a button which when clicked, runs the following code
startActivity(new Intent(this, ActivityA.class));
So when the app is started and the user does the following:
In this case, do the Activities A and B hog the memory since they get started each time or is Android smart enough to know that an activity has already started and simply needs to be put on top of the stack?
So in other words, if memory does indeed gets clogged up, is there something like:
if(activity has already started)
{
doNotStartActivityButSimplyPutItAtTop();
}
else
{
startActivity(new Intent.....);
}
Upvotes: 1
Views: 76
Reputation: 46
The android system may release the resources from previous activity in the stack. To avoid losing the current state of the activity you may have to save it and then restore when the activity is recreated. See Recreating an Activity.
Upvotes: 0
Reputation: 34210
yes, your assumption is right android is capable of managing these activities and they are maintains proper stack for it.
if you are having only two activities you can use singletop launcher mode so that only only two activities remain in stack.
Upvotes: 1