I am working on an app that supports Android API version 21 and above. Most of my background tasks have been designed with JobScheduler introduced in API 21.
I have recently come across JobIntentService introduces in API 26. The documentation says "When running on Android O or later, the work will be dispatched as a job via JobScheduler.enqueue. When running on older versions of the platform, it will use Context.startService."
What I want to understand is, why android is using JoScheduler only from API 26 and not from API 21. Is there a difference in JobScheduler on API 26 and above from that of the one introduced in API 21. Do I need to change any code to improve efficiency/avoid mistakes, converting my background jobs to use JobIntentService instead of Job Schedulers. I guess I do not understand the intention of what JobIntentService is trying to achieve.
答案 0 :(得分:8)
我不明白JobIntentService试图实现的目的
JobIntentService
旨在替代IntentService
/ WakefulBroadcastReceiver
组合,用于可能需要超过一分钟(但少于十分钟)的后台任务不希望使用前台服务。
为什么android只使用API 26而不是API 21
使用JoScheduler
只有谷歌可以回答这个问题,这就是为什么表格的问题"为什么开发者X做出决定Y?"对Stack Overflow不利。
注意"超过一分钟"问题出现在API Level 26+的背景限制上;在以前的版本中,没有这样的限制。
API 26及以上的JobScheduler与API 21中引入的不同
有些更改,包括一些使JobIntentService
能够正常工作的扩展程序。
我是否需要更改任何代码以提高效率/避免错误,将后台作业转换为使用JobIntentService而不是Job Schedulers
我不知道你为什么要从自己的JobService
切换到JobIntentService
。 JobIntentService
替代IntentService
,而不是JobService
。