[英]Why only the first activity's `onDestroy` is called, not other activities?
(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.我们可以按下一个按钮来开始另一个活动。
Like this: Activity1 -> Activity2 -> Activity3
像这样: Activity1 -> Activity2 -> Activity3
If we use the 'back' button, it calls the finish()
, so each activity's onDestroy()
gets called.如果我们使用“后退”按钮,它会调用finish()
,因此每个活动的onDestroy()
都会被调用。
But, if we close the app(by pushing the 'overview' button and then swipe the app out),但是,如果我们关闭应用程序(通过按下“概览”按钮然后将应用程序滑出),
only the Activity1
's onDestroy()
gets called.只有Activity1
的onDestroy()
被调用。
onDestroy()
of other activities are not called?为什么不调用其他活动的onDestroy()
? 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.理想情况下,当您从overview
中强制关闭App
时,它会杀死整个应用程序进程并且所有activities
都被销毁,并且您的活动堆栈根(即ActivityA
)的onDestroy
方法被调用,对于其他activities
,该method
不会被触发,但stack
本身与进程一起被破坏。 Nothing will be alive once the process is destroyed.一旦进程被破坏,没有任何东西是活着的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.