使用强制停止时未调用Android-Service-onDestroy()方法 [英] Android - Service - onDestroy() method not called when using Force Stop

查看:87
本文介绍了使用强制停止时未调用Android-Service-onDestroy()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用正在运行的服务"选项卡下的停止"按钮停止服务时,将调用onDestroy()方法.

When I stop a service using the stop button under the Running Services tab, the method onDestroy() is called.

但是当我强制停止应用程序时,永远不会调用onDestroy().

But when I force-stop the application, onDestroy() is never called.

对此有任何解释吗?

或者是强制停止时触发onDestroy()的解决方案?

or maybe a solution to fire onDestroy() when force-stopped?

谢谢!

推荐答案

当您强制停止应用程序时,确实发生了这种情况-这是强制停止".没有警告,没有回调,只是停止了.整个过程被杀死,并且没有向任何正在运行的组件(活动,服务等)发出警告.

When your force stop an app, exactly that happens - It is Force Stopped. No warning, no callbacks, just stopped. The entire process is killed, and none of the running components (Activities, Services etc) are given any warning.

绝对没有没有保证将调用 onDestroy().将所有应用程序关键代码移到 onPause()中,在大多数情况下会被调用.

There is absolutely no guarantee that onDestroy() will be called. Move any application critical code into onPause(), which is called under most circumstances.

这篇关于使用强制停止时未调用Android-Service-onDestroy()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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