如何使service不被杀掉?

flying_vip_521 2011-11-30 01:40:22
我在自己的应用中启了一个service,这个service是用来保护用户隐私的,所以该service不允许通过任务管理器等类似工具将service杀掉或停掉,求实现方法或思路,谢谢!
...全文
953 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
jdpxiaoming 2011-12-09
  • 打赏
  • 举报
回复
有意思,刚开始研究 framework 不发表意见
Rydiy 2011-12-09
  • 打赏
  • 举报
回复
提高service优先级就可以了,方法貌似是 setProcessPriority(-20) -20是仅次于系统的级别了
lingang1359 2011-12-08
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 menghen911 的回复:]

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

用线程实时监控Service状态,发现被KILL掉了就发广播给前台,接收到广播就start一下就可以了
menghen911 2011-12-08
  • 打赏
  • 举报
回复
在Setting在kill掉你正在运行的服务如何重启?
Calon Mo 2011-12-07
  • 打赏
  • 举报
回复
杀不掉应该做不了,但是杀掉再重启就可以做到
flying_vip_521 2011-12-07
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 zxciop110 的回复:]

3楼正解!
[/Quote]

何以见得是正解?有例有真相!
zxciop110 2011-12-07
  • 打赏
  • 举报
回复
3楼正解!
franzhong 2011-12-07
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 jayqean 的回复:]

引用 12 楼 kevinmcy 的回复:
杀不掉应该做不了,但是杀掉再重启就可以做到

+1
[/Quote]确实,除非从最底层写,不然系统就太不安全了,可以开机自启动
jayqean 2011-12-07
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 kevinmcy 的回复:]
杀不掉应该做不了,但是杀掉再重启就可以做到
[/Quote]
+1
xqhrs232 2011-12-05
  • 打赏
  • 举报
回复
弄成一个系统级的服务
maohuiabc 2011-12-05
  • 打赏
  • 举报
回复
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
allen1981813 2011-12-02
  • 打赏
  • 举报
回复
用Foreground Service吧。
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.html
有个例子的。

抛个Notification 上去,但是不同于一般的Notification,她必须用setForeground来关掉。一般的cancel是不起作用的。
flying_vip_521 2011-12-01
  • 打赏
  • 举报
回复
顶起来,求解呀。。。。。。。。。。。。。
flying_vip_521 2011-12-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mycourage1 的回复:]

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

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

难道就没有别的解决方案么?
mycourage1 2011-12-01
  • 打赏
  • 举报
回复
java层是无法实现的,即使实现了,也就成流氓软件了。 如果能更改init.rc, 可以实现成杀掉后能立即重启。再有就是可以改内核,让kill 无效,把 自己弄成和init进程一样。
flying_vip_521 2011-11-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ncuboy045wsq 的回复:]

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

启动了一个线程,调用了setDaemon(true),经过测试,还是不行呀,直接就kill掉了
flying_vip_521 2011-11-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ziyouzhifeng007 的回复:]

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


如何被强制kill掉进程,是不掉用onDestroy方法的
安卓机器人 2011-11-30
  • 打赏
  • 举报
回复
可以试试在Service里放一个守护线程,把需要的代码写进这个守护线程
ziyouzhifeng007 2011-11-30
  • 打赏
  • 举报
回复
这个很简单 在onDestroy方法里面再start一下service就不会被杀掉了。
儿大不由爷 2011-11-30
  • 打赏
  • 举报
回复
和手机厂商合作

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧