Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JobScheduler and JobIntentService

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.

like image 476
tacticurv Avatar asked Jan 15 '18 18:01

tacticurv


People also ask

How do I schedule a background job using JobScheduler?

There are some ways to do it. One of the simplest method is by creating a JobService which is scheduled by a JobScheduler. To use JobScheduler, the Android version must be at least version 5.0 Lollipop or above. This tutorial shows you how to schedule a background job using JobScheduler

What is jobintentservice in Android?

You can say JobIntentService is a modern way to run the background service from the background application. JobIntentService works in the same way as a Service however it enqueues the work into the JobScheduler on compatible Android targets ( SDK 26 or more).

What are the JobScheduler policies for running a job?

When running as a Job, it will be subject to standard JobScheduler policies for a Job with a JobInfo.Builder.setOverrideDeadline (long) of 0: the job will not run while the device is dozing, it may get delayed more than a service if the device is under strong memory pressure with lots of demand to run jobs.

What is JobScheduler in Android Lollipop?

Android Lollipop introduced JobScheduler as a part of optimizing background behavior. This task required conditions and factors ( JobInfo) and the operation of the condition ( JobService) running in the background. It will be executed at the appropriate time by the Android framework.


1 Answers

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.

like image 122
CommonsWare Avatar answered Oct 01 '22 19:10

CommonsWare