Android 应用程序中的 Stackoverflow 错误
在我的应用程序中,我只是在两个活动(即 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
启动新活动时,它将被推送到当前任务堆栈的顶部。如下图所示,
最终您的任务堆栈空间将耗尽,从而导致 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,
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.