应用行动中丧生的android行动中、android

2023-09-05 02:18:47 作者:谁走我都欣然放手i

我要执行的操作/事件时,应用程序从任务管理器或任何其他应用程序丧生。是否有任何执行操作时,应用程序被杀害。我的应用程序运行在后台般的服务。如果我终止应用程序,然后主要的服务站。我想再次启动它。

I want to perform action/event when application killed from task manager or any other app. Is there any to perform action when application killed. My application is running in background like service. If i terminate the application then main service stop . I want to start it again.

推荐答案

没有,有没有可靠的方法来知道你的应用程序被杀害了一个又一个的过程。一个应用程序的杀整点是要尽快终止它,不让它运行任何code。

No, there's no reliable way to know if your application was killed by a another process. The whole point of "killing" an app is to terminate it as soon as possible, without letting it run any code.

==不实际使用在生产中的应用提出以下建议。他们在这里纯粹是为潜在的技术解决方案,但一般不用于最终用户设备上运行的应用是一个好主意。 ==

有可能可以使用IBinder.linkToDeath()从辅助应用,其作为对您的主之一的监视器。但是,你必须说服用户安装辅助应用程序也是如此。如果你能做到这一点,你可以建立两个应用程序之间的两方监控,并让他们中的一个重新启动其他如果第二个被杀害。

It might be possible to use IBinder.linkToDeath() from a secondary application, which acts as a monitor for your primary one. However, you will have to convince the user to install the secondary app as well. If you can do it, you could establish two-side monitoring between the two apps, and have one of them restart the other if the second is killed.

您也可以尝试设置通过AlarmManager将触发每隔一段时间,如果发生被杀害,以重新启动应用程序。但是,如果您的报警时间是太大了,你可能有一定的时间,你的应用程序没有运行。如果你的时间太少,最有可能您的应用程序将无法在谷歌Play商店,手机(JB +)可能会踢上恶意软件的应用分析。同样,踢过于频繁的报警将保持允许谷歌该设备唤醒,并耗尽电池非常快的。

You could also attempt to set an alarm through the AlarmManager that fires every so often, to restart your application if it happens to be killed. However, if your alarm period is too big, you risk having certain period of time where your app is not running. And if your time period is too small, most likely your app will not be allowed by Google in the Google Play Store, and the malware app analysis on the phone (JB+) might kick in. Also, alarms that kick in too often will keep the device awaken, and drain the battery very fast.