无尽的活动计划

发布于 2024-12-12 03:18:04 字数 889 浏览 0 评论 0原文

在我的应用程序中,能够拥有无限的活动堆栈。场景是,您从一个用户的页面开始,该页面包含该用户的“朋友”列表。然后你可以点击一个朋友进入他们的页面,这看起来就像之前的页面,然后你可以点击另一个朋友进入他们的页面,依此类推......

我面临的大问题是一个无休止的问题本机堆。我相信每次视图膨胀时我都会添加到这个堆中。经过几次迭代后,我不断收到 OOM 错误,所以我必须找到某种解决方案。诀窍是,我想至少保留最后几项活动以浏览一些历史记录。

我能想到的最好办法是监视活动堆栈,然后在达到某个点时开始完成活动。这听起来像是一个可靠的方法吗?或者谁能进一步指出我该方法或另一种方法的实现?

谢谢

编辑:

堆栈非常简单。单击列表行(朋友),转到他们的页面。这是使用普通的 startActivity 调用,其意图是访问您所在的同一页面,以及带有用户 ID 的额外意图,然后调用数据库或远程 api 调用来获取用户的数据。

另外,为了跟进 Dalvik 与 Native,我会在导航期间定期检查 meminfo 转储。我将 dalvik 堆保持得尽可能小,并清理 onStop 中的资源。本机堆增长得更快。我在任何地方都没有对位图的硬引用,但屏幕上有很多来自通货膨胀的可绘制对象。这些drawable最终会导致android杀死我的activity吗?据我所知,它们只会导致 OOM,而我的任何活动都不会被预防性破坏。

如果我可以手动销毁我的活动,而不是仅仅停止它们(正如 Android 声称在内存不足时所做的那样),并将被销毁的活动保留在堆栈上并保存状态,那就太理想了。

再次编辑:

另一个关键是这些活动将混合有其他活动,例如

用户 -> 。用户->活动一->用户->活动b->用户

,这就是为什么我想利用内置堆栈,所以我知道什么时候必须进入用户活动,什么时候不需要。

In my app there is the ability to have an endless activity stack. The scenario is that you start on one user's page which has a list of people that are "friends" of that user. You can then click on a friend to go to their page, which looks just like the previous one, where you can then click on another friend to go to their page, and so on...

The big problem I am facing is an endless native heap. I believe I am adding to this heap everytime a view is inflated. After a few iterations of this, I am getting OOM errors consistently, so I have to find some kind of solution. The trick is, I want to maintain the last few activities at minimum for navigating some history.

The best I can come up with is monitor the activity stack, and then start finishing activities when it reaches a certain point. Does that sound like a solid approach, or even further can anyone point me to an implementation of that or another approach?

Thanks

edit:

The stack is very simple. Click on a listrow (a friend), go to their page. This is using a normal startActivity call with an intent to the same page you are on, and an intent extra with the user id that will then call the database or a remote api call to get the user's data.

Also, to follow up about Dalvik vs Native, I am routinely checking the meminfo dump during my navigation. I am keeping the dalvik heap as small as possible, cleaning out resources in onStop. The native heap grows much quicker. I have no hard references to bitmaps anywhere, but quite a few drawables on the screen from inflations. Would these drawables lead to android killing my activity eventually? As best I can tell they just lead to OOM without any of my activities being destroyed preventatively.

If I could manually destroy my activities instead of just stopping them (as Android claims to do when low on memory), and keep the destroyed activity on the stack with the state saved, that would be ideal.

edit again:

another key is that these activities will have other activities mixed in with them e.g.

user -> user -> activity a -> user -> activity b -> user

so that is why I want to make use of the built in stack, so I know when I have to go to a user activity and when I don't.

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

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

发布评论

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

评论(2

自由如风 2024-12-19 03:18:04

如何制作此活动singleInstance,拦截KeyEvent.KEYCODE_BACK,为此活动构建自己的后退按钮堆栈

我在这里做了一些示例:

http://esilo.pl/selvin/endlessactivity.zip

how about making this activity singleInstance, intercept KeyEvent.KEYCODE_BACK, build own back button stack for this activity

i made some example here:

http://esilo.pl/selvin/endlessactivity.zip

空城之時有危險 2024-12-19 03:18:04

我认为您遇到的 OOM 问题与您打开的活动数量无关。随着内存压力的增加,Android 应该销毁后台中的所有旧活动。当用户通过任务堆栈返回时,这些活动将被重新创建。

您是否使用过 MAT(内存分析工具)之类的工具来检查您在应用程序运行时分配的内容。我怀疑您可能存在内存泄漏,或者您可能必须在内存分配方面更加聪明。

I don't think the OOM problem you are experiencing is related to the number of Activities you have open. Android should be destroying any old activities in the background as memory pressure increases. These Activities will then just be re-created when the user returns back through the task stack.

Have you used a tool like MAT (memory analyzer tool) to examine what you have allocated during the runtime of your application. I suspect that you may have a memory leak, or that yo may have to be smarter in your memory allocations.

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