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.
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
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).
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With