JobScheduler and JobIntentService

吃可爱长大的小学妹 提交于 2020-01-13 01:55:10

问题


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.


回答1:


I do not understand the intention of what JobIntentService is trying to achieve

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.

why android is using JoScheduler only from API 26 and not from API 21

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.

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.

Is there a difference in JobScheduler on API 26 and above from that of the one introduced in API 21

There have been changes, including some extensions that enable JobIntentService to work.

Do I need to change any code to improve efficiency/avoid mistakes, converting my background jobs to use JobIntentService instead of Job Schedulers

I do not know why you would switch from your own JobService to JobIntentService. JobIntentService is a replacement for IntentService, not for JobService.



来源:https://stackoverflow.com/questions/48268657/jobscheduler-and-jobintentservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!