Android活动堆栈大小问题?
我有一个包含很多活动的应用程序。其中许多活动可以启动其他活动,因此用户期望生成相当大的活动堆栈。
我目前正在使用默认的活动启动行为。有人知道大型活动堆栈(如> 100)是否会造成问题吗?这有限制吗?它会降低性能、导致 ANR 对话框或类似的情况吗?
谢谢
I have an application with lots of activities. Many of these activities can start others, so the user's expected to generate a quite large activity stack.
I'm currently using the default activity launch behaviours. Does anybody know, if a large activity stack (like > 100) would be pose a problem? Is there a limit to this? Would it decrease performance, cause an ANR dialog, or something like that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 在需要释放内存或其他资源时会终止 Activity。根据 Activity 生命周期,Activity 有资格被杀死:当它不再可见时。
假设您正确处理了 Activity 的终止和重新启动,那么应该没问题。
顺便说一句,我很难从用户的角度想出一个用例,我可以在其中访问 > >一个应用程序中有 100 项活动...
Android will kill Activities when it needs to to free up memory or other resources. Per the Activity Lifecycle, and Activity is eligible to be killed as soon as it is no longer visible.
Assuming you correctly handle the killing and restarting of Activities, you should be fine.
As an aside, I struggle to come up with a use case from a user's perspective where I would access > 100 activities in one app...
Mayra 对于这个问题的推理是错误的。只要活动来自与当前运行的应用程序不同的应用程序,Android 就会从堆栈中终止这些活动。
因此,如果您的应用程序打开 100 个活动,这 100 个活动将保留在堆栈中,并且您很可能会发现 OutOfMemoryError。
尝试以不同的方式构建您的应用程序。
Mayra's reasoning is wrong for this problem. Android kills activities from the stack as long as they are activities from a different application that the one currently running.
Therefore, if your application opens 100 activities, the 100 will be kept in the stack, and most probably you'll find OutOfMemoryError's.
Try to structure your app differently.