Android - 判断父活动是否已被销毁

发布于 2024-11-16 07:16:00 字数 447 浏览 4 评论 0原文

因此,我编写了一个应用程序,它具有主活动 (A) 和各种其他子活动,它们都执行某些操作,将工作报告回主活动,然后完成。

我遇到的情况是,如果用户将我的应用程序留在屏幕 B 或 C,当他们稍后返回时,dalvik 已经销毁了我的活动以获取更多 RAM...应用程序从 B 或 C 重新启动,并读取保存的意图中的所有初始化内容,然后继续,就像什么都没发生一样。直到他们回到活动A,在那里我们从意想不到的事情中获得了接近的力量。

我已经摆弄了重写 onStop() 和调用 finish,但我认为这有点焦土,我想让他们离开该活动然后再回来。但我还想检测底层主要活动是否已被销毁,然后销毁我的整个活动堆栈。

通过阅读周围的内容,我发现 onDestroy() 并不总是被调用,因此我在 Activity A 的 onDestroy 中插入一些逻辑对我来说并不可靠......有什么想法吗?

So, I have written an app that has a Main activity (A), and various other sub-activities that all do something, report the work back to main, and finish.

What I am running into is that if the user leaves my app at Screens B or C, when they come back at a later time and dalvik has destroyed my activities for more RAM... the app starts back at B or C, and reads all the initialization stuff from the saved intent, and continues on as if nothing happened. Until they return back to activity A, where we get a force close from unexpected things.

I've twiddled with overriding onStop() and calling finish, but i think this is a bit scorched earth, I'd like to let them leave on that activity and come back. But i'd also like to detect if the underlying main activity has been destroyed, and then destroy my entire activity stack.

From reading around, I get the idea that onDestroy() is not always called, so it isnt reliable for me to insert some logic into Activity A's onDestroy.... Any ideas?

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

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

发布评论

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

评论(1

眼眸 2024-11-23 07:16:00

尝试使用标记 FLAG_ACTIVITY_NO_HISTORY 启动子活动 B 和 C。

Try starting your sub activities B and C with the flag FLAG_ACTIVITY_NO_HISTORY.

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