问题描述
- 怎么防止service被kill?
- android 开发程序,怎么防止service被kill?有一些安全软件,会清理软件,这样的话,自己的程序就会被干掉,如何解决?或者被干掉后,立马可以启动它
解决方案
http://bbs.csdn.net/topics/380088739
这个论坛帖你可以点击进去看看它需要解决的和你一样的问题而且有解决的办法;
如果回答对您有帮助请采纳
解决方案二:
服务器怎么允许安装乱七八糟的软件?这本身就是很不严肃的。如果说连拥有管理员权限的人都胡作非为,那么这个问题根本没有讨论的必要了。
解决方案三:
sorry,看错了。理论上说,你首先应该取得“安全软件”的信任。因为在“安全软件”不同意的情况下,如果有这样的技术,意味着写病毒的人也知道这种技术,那么安全软件不能阻止还有存在的意义么?
如果你是防止意外关闭,而不是和另一个软件打架,那么这个可以使用看护进程实现,看护进程发现主程序没了就启动一个,反过来,主程序看护看护进程。看护进程没了,主程序启动一个看护进程,这样就保证了主程序不会中断。
解决方案四:
官网解释
A started service must manage its own lifecycle. That is the system does not stop or destroy the service unless it must recover system memory and the service continues to run after onStartCommand() returns. So the service must stop itself by calling stopSelf() or another component can stop it by calling stopService().
The Android system will force-stop a service only when memory is low and it must recover system resources for the activity that has user focus. If the service is bound to an activity that has user focus then it's less likely to be killed and if the service is declared to run in the foreground then it will almost never be killed. Otherwise if the service was started and is long-running then the system will lower its position in the list of background tasks over time and the service will become highly susceptible to killing—if your service is started then you must design it to gracefully handle restarts by the system. If the system kills your service it restarts it as soon as resources become available again (though this also depends on the value you return from onStartCommand()) .
也就是说.Service分为3种。
a>startService。
除了通过stopself()和stopService()关闭service外还可以通过onStartCommand()返回的值来控制开关service。
b>boundService
只能通过stopself()和unBind来关闭service。
c>foregroundService
只能通过stopForegroundService()关闭