我在自己的应用中启了一个service,这个service是用来保护用户隐私的,所以该service不允许通过任务管理器等类似工具将service杀掉或停掉,求实现方法或思路,谢谢!

解决方案 »

  1.   

    这个很简单 在onDestroy方法里面再start一下service就不会被杀掉了。
      

  2.   

    可以试试在Service里放一个守护线程,把需要的代码写进这个守护线程
      

  3.   

    如何被强制kill掉进程,是不掉用onDestroy方法的
      

  4.   


    启动了一个线程,调用了setDaemon(true),经过测试,还是不行呀,直接就kill掉了
      

  5.   

    java层是无法实现的,即使实现了,也就成流氓软件了。 如果能更改init.rc, 可以实现成杀掉后能立即重启。再有就是可以改内核,让kill 无效,把 自己弄成和init进程一样。
      

  6.   


    在Smart App Protector这个应用中,当通过settings杀掉应用或service时,会立即重启;而通过其他的程序如TaskKiller对应用进行杀掉时,则无效。它的实现原理是不是就是通过更改init.rc 文件来实现的呢?如果是的话,存在两个问题:一是如何在自己的应用中修改init.rc文件,二是修改init.rc文件是否需要重新编译才生效。如果修改内核的话,应该怎么做,自己的应用中能实现么,如果更改内核,应该也同样有编译问题吧。难道就没有别的解决方案么?
      

  7.   

    用Foreground Service吧。
    http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.html
    有个例子的。抛个Notification 上去,但是不同于一般的Notification,她必须用setForeground来关掉。一般的cancel是不起作用的。
      

  8.   

    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
      

  9.   

    在Setting在kill掉你正在运行的服务如何重启?
      

  10.   


    用线程实时监控Service状态,发现被KILL掉了就发广播给前台,接收到广播就start一下就可以了
      

  11.   

    提高service优先级就可以了,方法貌似是 setProcessPriority(-20)  -20是仅次于系统的级别了
      

  12.   

    有意思,刚开始研究 framework 不发表意见