How to remove the Activity in the bottom of the Activity Stack?

868 Views Asked by At

In my application I have about a dozen of Activities. However, most of these have some shortcut-buttons, so the user can start the most important ones from anywhere in the app. This means, that the user can just jump around the app., filling up the Activitiy Stack with Activities. I can't change this behaviour, because I need the history function the stack provides (so I can't just use the noHistory option).

Obviously, I'd like to do something against this possible memory leak. Is it possible to remove the entry from the bottom of the Activity Stack, if the stack's size is greater than a certain number? So the stack only remembers the newest X (e.g. 30) Activity?

Thanks

2

There are 2 best solutions below

3
On BEST ANSWER

Obviously, I'd like to do something against this possible memory leak.

What possible memory leak? Android will destroy activities as needed to reclaim memory. If the user BACK-buttons their way to one Android destroyed, the activity will be recreated with its original Intent and passed the Bundle you filled in via onSaveInstanceState().

Is it possible to remove the entry from the bottom of the Activity Stack, if the stack's size is greater than a certain number? So the stack only remembers the newest X (e.g. 30) Activity?

Not that I am aware of. Again, you should not need it.

0
On

History Stack will be managed by Android Runtime; you do not have to worry about that.

However, if you have launched an activity earlier and want to bring it to the front, you can do this by setting appropriate Intent Flags(like ACTIVITY_FLAG_REORDER_TO_FRONT). That way you would not have duplicate Activities on the stack when not desired. Note that, this will affect the chronology/linear nature of history.