问题描述
我正在开发一个支持Android API版本21及更高版本的应用程序.我的大多数后台任务都是使用API 21中引入的JobScheduler设计的.
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.
我最近遇到过API 26中引入的JobIntentService.文档说:在Android O或更高版本上运行时,将通过JobScheduler.enqueue将工作作为作业分派.在平台的旧版本上运行时,它将使用Context.startService."
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."
我想了解的是,为什么Android仅使用API 26而不使用API 21的JoScheduler?与API 21中引入的JobScheduler相比,API 26及更高版本的JobScheduler是否有所不同?更改任何代码以提高效率/避免错误,将我的后台作业转换为使用JobIntentService而不是Job Schedulers.我想我不明白JobIntentService试图达到的目的.
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.
推荐答案
JobIntentService
旨在代替 IntentService
/ WakefulBroadcastReceiver
组合,用于可能需要一分钟以上的后台任务(但少于十)并且您不希望使用其前台服务.
JobIntentService
is meant to be a replacement for the IntentService
/WakefulBroadcastReceiver
combination, for background tasks that might take more than a minute (but less than ten) and for which you do not wish to use a foreground service.
只有Google可以回答,这就是为什么出现以下形式的问题:开发人员X为什么做出决策Y?"对堆栈溢出不利.
Only Google can answer that, which is why questions of the form "why did Developer X make Decision Y?" are not good for Stack Overflow.
请注意,超过一分钟"的问题是由API级别26+的背景限制引起的;在以前的版本中,没有这样的限制.
Note that the "more than a minute" issue arises with the background limitations on API Level 26+; on previous versions, there was no such limit.
进行了一些更改,包括使 JobIntentService
正常工作的一些扩展.
There have been changes, including some extensions that enable JobIntentService
to work.
我不知道您为什么要从自己的 JobService
切换到 JobIntentService
. JobIntentService
是 IntentService
的替代品,而不是 JobService
.
I do not know why you would switch from your own JobService
to JobIntentService
. JobIntentService
is a replacement for IntentService
, not for JobService
.
这篇关于JobScheduler和JobIntentService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!