我怎样才能prevent被&QUOT我的Andr​​oid应用程序/服务;杀"从任务管理器?我的、应用程序、任务管理器、prevent

2023-09-04 08:47:50 作者:尘烟染暮雪

这是非常重要的,我的服务保持运行,直到有人用密码从我的UI画面停止服务。我的应用程序运行很好,但它被设计在他们的孩子手机被导通/截止由父母(用密码)。我已成功地使一切工作,但我遇到的问题是,如果孩子使用任务管理器杀了我的服务的话,我的应用程序是没有用的。我将不胜感激谁知道一种方法来

It is very important that my service stay running until someone with a password stops the service from my UI screen. My app runs great but it is designed to be turned on/off by parents (with a password) on their kids phones. I have managed to make everything work but the problem I'm having is that if the kid uses a task manager to kill my service then my app is useless. I would be grateful to anyone who knows a way to either

1)监控服务,并重新启动它会自动如果封杀 要么 2)prevent有人能杀死它除了从活动(管理屏幕),其推出的服务。还是两者兼而有之?

1) monitor the service and start it back up automatically if its "killed" or 2) prevent someone from being able to kill it except from the activity (administration screen) that launched the service. Or both?

我很抱歉,如果我不是在描述问题很清楚,我是个初学者。我到目前为止已经取得了很大的进展,但我停留在这最后一关。

I'm sorry if I'm not very clear in describing the problem, I'm a beginner. I've made great progress so far but I am stuck at this last hurdle.

推荐答案

您可以使用API​​方法: startForeground()。这里是它的解释:

You can use API method: startForeground(). Here is the explanation of it:

一个启动的服务可以使用startForeground(INT,通知)API   把服务在前台状态,其中该系统会考虑   它是什么,用户正在积极知道,因此不是   候选人内存查杀的时候低。 (它仍然是理论上   可能的服务,在极端的内存pressure被杀死   从目前的前台应用程序,但在实践中,这应该   不会成为问题。)

A started service can use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory. (It is still theoretically possible for the service to be killed under extreme memory pressure from the current foreground application, but in practice this should not be a concern.)

Here你可以找到一个例子如何使用此。

Here you can find an example how to use this.

至于这个问题,你不能prevent从服务被杀害。它可以由系统杀死。即使系统服务可以被杀死。如果发生这种情况,他们会重新启动。您可以使用同样的方法。

As for the question, you cannot prevent a service from being killed. It can be killed by the system. Even system services can be killed. If this happens they are restarted. You may use the same approach.

 
精彩推荐
图片推荐