仅当您显式调用finish()时才会调用onDestroy吗?还是有例外? [英] Is onDestroy called only if you explicitly call finish() ?? or are there any exceptions?

查看:207
本文介绍了仅当您显式调用finish()时才会调用onDestroy吗?还是有例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LocalBroadcastReceiver,我在ondestroy()中是unregistering.

现在,我读到了关于这两个SO答案中提到的ondestroy()的信息 is-ondestroy-not-经常被称为why-不保证要被实施的实现-ondestroy-if-it 以及

Now i read about ondestroy() mentioned in these two SO answers is-ondestroy-not-always-called and why-implement-ondestroy-if-it-is-not-guaranteed-to-be-called and as well as in Androi Docs that

如果您明确调用finish(),则会调用

onDestroy

onDestroy will be called if you explicitly call finish();

但是在我的情况下,为什么我没有调用finish()却仍然在所有的Android设备中每次都调用ondestroy().还要根据你们的情况,在什么情况下ondestroy()没有被调用.

But why in my case I am not calling finish() but still ondestroy() is getting called everytime in all of my Android devices. Also according to you guys where are the cases where ondestroy() not get called up.

即使Android会杀死我的应用程序(由于内存较少),我也不必担心,因为Android会杀死我的整个应用程序,因此接收方最终会被杀死.(因此不会有任何内存泄漏).

Also even if Android will kill my app(due to less memory) I don't need to worry as Android is going to kill my whole app so receiver will ultimately get killed.(So there won't be any Memory Leak).

因此,在我的用例中,有哪些情况不会调用ondestroy().

So for my use case which cases are there where ondestroy() is not going to get called up.

推荐答案

但是,在我的情况下,为什么我不调用finish()但仍然在所有Android设备中每次都调用ondestroy().

But why in my case I am not calling finish() but still ondestroy() is getting called everytime in all of the Android devices.

onBackPressed()的默认实现— BACK按钮触发了什么—呼叫finish().

The default implementation of onBackPressed() — what is triggered by the BACK button — calls finish().

在什么情况下不会调用ondestroy().

where are the cases where ondestroy() not get called up.

  1. 如果因未处理的异常而崩溃

  1. If you crash with an unhandled exception

如果您的进程以紧急方式终止(例如,系统需要RAM来处理传入的电话呼叫)

If your process is terminated in an urgent fashion (e.g., the system needs RAM to process an incoming phone call)

如果用户在设置"中的应用程序屏幕上单击强制停止"

If the user clicks "Force Stop" on your app's screen in Settings

在某些设备上,如果用户使用制造商提供的任务管理器终止您的过程

On a few devices, if the user terminates your process using a manufacturer-supplied task manager

即使Android会杀死我的应用程序(由于内存较少),我也不必担心,因为Android会杀死我的整个应用程序,因此接收者最终会被杀死

Also even if Android will kill my app(due to less memory) I don't need to worry as Android is going to kill my whole app so receiver will ultimately get killed

是的,因为您的整个过程将被终止.

Yes, because your entire process will be terminated.

这篇关于仅当您显式调用finish()时才会调用onDestroy吗?还是有例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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