android - IntentService + startForeground 与 JobIntentService

标签 android android-service intentservice android-intentservice android-jobscheduler

由于 Android Oreo 后台执行限制,文档建议将 IntentService 重构为 JobIntentService

https://developer.android.com/about/versions/oreo/background

JobIntentService 作为 IntentService 在 Oreo 下立即运行,但在 Oreo+ 上安排作业

https://developer.android.com/reference/android/support/v4/app/JobIntentService

在什么情况下将普通的 IntentService 作为具有持久通知的前台 Service 运行是有意义的,什么时候是 JobIntentService更好?

我在 JobIntentService 中看到的一个缺点是它不会立即启动。

最佳答案

前台服务不受 Doze 影响,但如果您需要在屏幕关闭时继续执行任务,您仍然必须使用唤醒锁。

JobIntentService(使用 JobScheduler)为您管理唤醒锁,但您对何时开始作业的控制较少。

我会将前台 IntentService(或服务)用于应立即运行且不应被系统暂停/终止的高优先级任务(例如下载数据库)。

我会结合使用 JobIntentService 和 AlarmManager 来安排低优先级任务,例如定期刷新小部件的数据。

关于android - IntentService + startForeground 与 JobIntentService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53248528/

相关文章:

android - 如何用C++编写Android服务

android - 从最近使用的应用程序中删除应用程序后,AlarmManager 停止

Android:从 NotificationManager 操作 PendingIntent 调用 IntentService

android - 如何将可绘制对象对齐到 TextView 中文本的左侧?

android - 带有简单适配器的 ListView 不显示文本

android - 在android中使用HttpPost发布JsonArray和字符串参数

android - 等到手机屏幕亮起

Android _ 从服务类重定向到另一个 Activity ?

android - WakefulBroadcastReceiver 中 IntentService 中的 BroadcastReceiver 并不总是有效

android - 一个 OnClickHandler 用于多个按钮