且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android:如何知道被高级任务杀手杀死的活动/服务?

更新时间:2021-11-28 02:40:02

我只想知道如何检测活动或服务已被高级任务杀手杀死?

I just want to know how detect that the activity or service has been killed by the advanced task killer?

以这种方式终止任务时,您不会收到任何通知.

You do not receive any notification when your task is killed in this fashion.

我期望调用onDestroy方法,但事实并非如此!

I was expecting the onDestroy method to be called, but it doesnt!

在许多情况下,将不会调用活动或服务的onDestroy().这就是其中之一.

There are various scenarios in which onDestroy() of an activity or service will not be called. This is one of them.

我的应用在启动时启动后台服务.

My app starts the background service on boot.

我衷心希望服务能在几秒钟后关闭.否则,请考虑是否您在做什么是正确的东西.

I sincerely hope that service shuts down in a few seconds. Otherwise, please consider whether what you are doing is the right thing.