Android 应用程序中的 Stackoverflow 错误

发布于 2024-11-29 12:35:24 字数 304 浏览 0 评论 0原文

在我的应用程序中,我只是在两个活动(即 A 和 B)之间运行。根据用户,他从 A 切换到 B,然后从 B 切换到 A,然后再次从 A 切换到 B,然后从 B 切换到 A,然后继续。

这两个活动都有列表视图。每次用户进入和退出时,我都会添加一些存储在数据库中的数据。这些数据是从 rss feed 中检索的,有时它们的数量非常多。因此,我很少遇到堆栈溢出错误。

起初,我通过相对布局设计了布局,并将列表视图放置在相对布局中。我在这里得到了一个答案,这个错误可能是由于相对布局造成的,所以我将所有布局更改为线性布局,但错误仍然发生。

如何克服这个问题

in my app i am just running between two activities namely A and B. As per the user he switches from A to B then B to A and again A to B then B to A and goes on.

Both these activities are having list views. Every time when the user gets in and gets out i am adding some data that gets stored in the database. Those data are retrieved from an rss feed, some times they use to be very high in number. Because of this rarely i am getting the stack over flow error.

At first i designed my layouts by Relative layout and i have placed my list views inside a relative layout. I got an answer here, that this error may be due to relative layout and so i changed all my layouts to be as linear layout but still the error is happening.

how to overcome this problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

作死小能手 2024-12-06 12:35:24

启动新活动时,它将被推送到当前任务堆栈的顶部。如下图所示,

                                                                 |->  B - StackOverflow
    | |                 | |               |A|                   |A|
    | |                 |B|               |B|                   |B|
    |A|                 |A|               |A|                   |A|
    ```                 ```               ```                   ```
Before launching   After launching    After launching       Trying to launch
 activity B         activity B         activity A            activity B

最终您的任务堆栈空间将耗尽,从而导致 stackoverflow 错误。

考虑使用一些意图标志来清除堆栈历史记录。根据您提供的数据,我认为标志应该很有帮助 - FLAG_ACTIVITY_NO_HISTORY。但您需要确认这是否是您想要的行为,只需浏览其余的活动标志并选择适合您的应用程序的正确标志即可。

When launching a new activity it is pushed on top of the current task's stack. As shown in the below figure,

                                                                 |->  B - StackOverflow
    | |                 | |               |A|                   |A|
    | |                 |B|               |B|                   |B|
    |A|                 |A|               |A|                   |A|
    ```                 ```               ```                   ```
Before launching   After launching    After launching       Trying to launch
 activity B         activity B         activity A            activity B

So eventually you will run out of space on your Task Stack which causes the stackoverflow error.

Consider using some of the intent flags to clear the Stack history. From your data you have given I think flag should be helpful - FLAG_ACTIVITY_NO_HISTORY. But you need to confirm if that is the behaviour you want, just go through the rest of the activity flags and choose the correct one that suits your application.

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