持续服务
我知道有些人的观点是你不应该创建持久性服务。
但对于我们这些想要增加知识的人来说,如何从理论上创造一个呢?
我一直在玩,注意到使用 startForeground 在内存不足的情况下被杀死。
我看到过一个现已弃用的权限 PERSISTENT_ACTIVITY
,但这并没有多大作用。
那么秘密是什么?
I know that some peoples view is that you should not create persistent services.
But for those of us that want to increase our knowledge, how does one go about creating one in theory?
I have been playing around, and noticed that services that use startForeground are killed in low memory situations.
I have seen a, now deprecated, permission PERSISTENT_ACTIVITY
, but that didn't do much.
So what is the secret?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在开发系统应用程序,则只能使您的服务持久化。这些服务基本上是不可杀死的,并且在“adb shell dumpsys Activity”命令的输出中被标记为“PERS”。它没有很好的记录,所以我快速写了一篇关于 Android 中的持久服务< /a>...希望它能帮助一些人。
但对于非系统应用程序,startForeground 是您的最佳选择。
You can only make your service persistent if you are developing system apps. These services will be basically un-killable, and are labeled as "PERS" in the output of the "adb shell dumpsys activity" command. It's not very well documented, so I did a quick write-up on Persistent services in Android...hopefully it will help some people out.
But for non-system apps, startForeground is your best option.
绝对没有办法阻止操作系统杀死您的服务。
There is absolutely no way of preventing the OS from killing your service.