持续服务 [英] Persistent service

查看:18
本文介绍了持续服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有些人的观点是不应该创建持久化服务.

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?

我一直在玩,并注意到使用 startForeground 在内存不足的情况下被杀死.

I have been playing around, and noticed that services that use startForeground are killed in low memory situations.

我看到了一个现已弃用的权限 PERSISTENT_ACTIVITY,但这并没有多大作用.

I have seen a, now deprecated, permission PERSISTENT_ACTIVITY, but that didn't do much.

那么秘诀是什么?

推荐答案

只有在开发系统应用程序时,才能使服务持久化.这些服务基本上是不可杀死的,并在adb shell dumpsys activity"命令的输出中标记为PERS".它没有很好的文档记录,所以我快速写了一篇关于 Android 中的持久服务...希望它能帮助一些人.

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.

但对于非系统应用程序,startForeground 是您的最佳选择.

But for non-system apps, startForeground is your best option.

这篇关于持续服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆