专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Android

怎么使service不被杀掉

发布时间:2010-05-30 10:56:12 文章来源:www.iduyao.cn 采编人员:星星草
如何使service不被杀掉?
我在自己的应用中启了一个service,这个service是用来保护用户隐私的,所以该service不允许通过任务管理器等类似工具将service杀掉或停掉,求实现方法或思路,谢谢!

------解决方案--------------------
用Foreground Service吧。
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.html
有个例子的。

抛个Notification 上去,但是不同于一般的Notification,她必须用setForeground来关掉。一般的cancel是不起作用的。
------解决方案--------------------
Running a Service in the Foreground
A foreground service is a service that's considered to be something the user is actively aware of and thus not a candidate for the system to kill when low on memory. A foreground service must provide a notification for the status bar, which is placed under the "Ongoing" heading, which means that the notification cannot be dismissed unless the service is either stopped or removed from the foreground.

For example, a music player that plays music from a service should be set to run in the foreground, because the user is explicitly aware of its operation. The notification in the status bar might indicate the current song and allow the user to launch an activity to interact with the music player.

To request that your service run in the foreground, call startForeground(). This method takes two parameters: an integer that uniquely identifies the notification and the Notification for the status bar.

详细请参考http://developer.android.com/guide/topics/fundamentals/services.html
------解决方案--------------------
探讨
杀不掉应该做不了,但是杀掉再重启就可以做到
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: