简体   繁体   English

为什么只调用第一个活动的`onDestroy`,而不调用其他活动?

[英]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.只有Activity1onDestroy()被调用。

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

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.

相关问题 为什么要调用新Activity的onDestroy()? - Why new Activity's onDestroy() is called? 片段的onActivityCreated()在Activity的onDestroy()之后调用 - Fragment's onActivityCreated() is called after onDestroy() of Activity 为什么当我们关闭应用程序时在android中只调用主要活动ondestroy - why only main activity ondestroy is called in android when we close the app 并非总是调用Android Activity onDestroy(),如果调用,则仅执行部分代码 - Android Activity onDestroy() is not always called and if called only part of the code is executed Activity OnDestroy从未调用过? - Activity OnDestroy never called? 当其他活动打开时,从未调用过OnPause()和onDestroy() - OnPause() and also onDestroy() never called when other activity opened 从后台滑动后未调用Activity的onDestroy方法 - Activity's onDestroy method is not being called after swiping from background 如果未调用活动的 onDestroy() 方法,如何更新远程数据库中的状态? - How to update status in remote database if the activity's onDestroy() method is not called? 当我单击通知并进入活动时,为什么调用onDestroy()? - Why is onDestroy() called when I click on a notification and go to my activity? 在PAD中返回父活动时为何调用onDestroy? - Why onDestroy called when returning to parent activity in PAD?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM