如何移除Activity Stack底部的Activity?
在我的应用程序中,我有大约十几个活动。然而,其中大多数都有一些快捷按钮,因此用户可以从应用程序中的任何位置启动最重要的按钮。这意味着,用户可以在应用程序中跳转,用“活动”填充“活动堆栈”。我无法改变这种行为,因为我需要堆栈提供的历史功能(所以我不能只使用 noHistory 选项)。
显然,我想针对这种可能的内存泄漏采取一些措施。如果堆栈的大小大于某个数字,是否可以从活动堆栈底部删除该条目?那么堆栈只记住最新的X(例如30)个Activity?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有什么可能的内存泄漏? Android 会根据需要销毁 Activity 以回收内存。如果用户按后退按钮到达一个被销毁的 Android,则该 Activity 将使用其原始
Intent
重新创建,并传递您通过onSaveInstanceState()
填写的 Bundle。据我所知,情况并非如此。再说一次,你不应该需要它。
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 viaonSaveInstanceState()
.Not that I am aware of. Again, you should not need it.
History Stack将由Android Runtime管理;你不必担心这一点。
但是,如果您之前启动了某个 Activity 并希望将其置于最前面,则可以通过设置适当的 意图标志(如 ACTIVITY_FLAG_REORDER_TO_FRONT)。这样,当不需要时,堆栈上就不会出现重复的 Activity。请注意,这将影响历史的年代/线性性质。
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.