Android活动堆栈大小问题?

发布于 2024-10-14 09:49:28 字数 155 浏览 3 评论 0原文

我有一个包含很多活动的应用程序。其中许多活动可以启动其他活动,因此用户期望生成相当大的活​​动堆栈。

我目前正在使用默认的活动启动行为。有人知道大型活动堆栈(如> 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提赋 2024-10-21 09:49:28

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...

攒眉千度 2024-10-21 09:49:28

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文