为什么只调用第一个活动的“onDestroy",而不调用其他活动? [英] Why only the first activity's `onDestroy` is called, not other activities?

查看:39
本文介绍了为什么只调用第一个活动的“onDestroy",而不调用其他活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我搜索了很多,但似乎没有确切的答案.)

(I searched quite a bit, but there seems no exact answer for this.)

假设有一个应用程序.我们可以按下一个按钮来启动另一个活动.

Let's say there's an app. We can push a button to start another activity.

像这样:Activity1 ->活动 2 ->Activity3

如果我们使用后退"按钮,它会调用finish(),因此每个活动的onDestroy() 都会被调用.

If we use the 'back' button, it calls the finish(), so each activity's onDestroy() gets called.

但是,如果我们关闭应用程序(通过按下概览"按钮然后将应用程序滑出),

But, if we close the app(by pushing the 'overview' button and then swipe the app out),

只有 Activity1onDestroy() 被调用.

only the Activity1's onDestroy() gets called.

  1. 为什么不调用其他活动的 onDestroy()?
  2. 这是否意味着其他活动在系统杀死它们之前活着?(如果系统有足够的资源,它们不会被破坏?)
  1. Why the onDestroy() of other activities are not called?
  2. Does it mean that other activities are alive until the system kills them? (If the system has enough resources, they are not destroyed?)

推荐答案

理想情况下,当您从 overview 强制关闭 App 时,它会杀死整个应用程序进程和所有activities 被销毁,并且您的活动堆栈根(即 ActivityA)的 onDestroy 方法被调用并用于其他 activitiesmethod 不会被触发,但 stack 本身会随着进程被销毁.一旦进程被销毁,任何东西都将不复存在.

Ideally when you force close the App from overview, it kills the entire app process and all the activities are destroyed, and your activity stack root's(which is ActivityA) onDestroy method is called and for other activities the method won't be triggered but the stack itself gets destroyed along with the process. Nothing will be alive once the process is destroyed.

这篇关于为什么只调用第一个活动的“onDestroy",而不调用其他活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆