如何防止用户在android中强制停止服务?
我有一个要求,我希望在后台连续运行服务,并且它不能由用户置顶,也不能通过进入管理应用程序来强制停止。当用户尝试强制停止服务时,有什么方法可以收到通知吗?或者任何在android中隐藏我们的应用程序的方法。
我已经完成了 START_STICKY 但它不起作用。 是否可以在无法杀死的 Android 系统服务(或系统代码)或内核级编码上编写我们的代码?
我的主要标准是我的服务不能被用户终止,
请帮助我
提前致谢
i have a requiremet that i want run service continuously in backgroud and it cannot be top by user or it cannot be force stop by going in manage application. is there any way to get notification when user is trying force stop service? or any way to hide our application in android.
i have done START_STICKY but it can't work.
it can be possible to write our code on android system services(or system code) that can't be killed or kernel level coding ?
my main criteria is that my service cannot be killed by user
please help me in this
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果托管服务的进程处于内存不足的情况,它总是可以被系统杀死。您的服务甚至不会注意到它已被杀死,它甚至不会得到 onDestroy()。如果您的服务正在做最终用户直接知道的事情(例如播放音乐),您应该在前台启动该服务(使用startForeground),以减少系统在内存不足的情况下杀死它的可能性。
如果服务被最终用户或系统终止,它将在需要时或有可用资源时再次重新启动。
话虽如此,根据设计,您想要做的事情是不可能的。要么你的标准是基于对 Android 工作原理的一些误解,要么你的应用程序应该做一些它想对最终用户隐藏的事情(这是非常值得怀疑的)。
First of all, a process hosting a service can always be killed by the system if it is in a low memory situation. You service will not even notice that it has been killed, it won't even get onDestroy(). If your service is doing something that the end user is directly aware of (e.g. playing music) you should start the service in foreground (using startForeground) to make it less likely that the system will kill it in a low memory situation.
If a service gets killed by the end user or the system, it will be restarted again when needed or when there are resources available.
Having that said, what you want to do isn't possible, by design. Either your criteria is based on some misunderstanding of how Android works, or your application is supposed to do something that it wants to hide from the end user (which is very questionable).