开发者

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

开发者 https://www.devze.com 2023-02-11 07:04 出处:网络
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 us

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开发者_如何学JAVA 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消