Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compatible version of Android JobScheduler - alternative [closed]

Is there a library or at least some open source example that provides functionality of new Android-L JobScheduler API. It is not to hard to implement my own version (with very limited functionality) but on the other hand it is not trivial either.

So to sum it up is there anything that at least can provide subset of functions of new JobScheduler API ?

like image 540
Gordon Freeman Avatar asked Aug 08 '14 12:08

Gordon Freeman


People also ask

What is the difference between WorkManager and JobScheduler in Android?

As mentioned in the previous section, WorkManager internally uses the JobScheduler API on Android 6.0 (API Level 23 – Marshmallow) and above devices. Therefore, there won't be any major differences between the WorkManager and JobScheduler on Android 6.0 and above devices. Both would behave in the same way.

What is JobScheduler in Android?

android.app.job.JobScheduler. This is an API for scheduling various types of jobs against the framework that will be executed in your application's own process. See JobInfo for more description of the types of jobs that can be run and how to construct them.

Which API is used to schedule Android jobs?

The job scheduler API. The Android 5.0 Lollipop (API 21) release introduces a job scheduler API via the JobScheduler class. This API allows to batch jobs when the device has more resources available.


2 Answers

Just use GCM Network Manager. It provides APIs to schedule tasks. It is available on pre API level 21 devices. On API level 21+ devices it uses Job Scheduler internally.

like image 58
Nouman Hanif Avatar answered Oct 27 '22 15:10

Nouman Hanif


You can do some of it yourself, but unfortunately an app cannot itself achieve comparable functionality to a lot of the job scheduler API. The problem is that monitoring several of the execution criteria that the job scheduler provides (notably charging state, device idleness, and connectivity) would require that your app be running constantly just to receive the broadcasts about those states -- and the performance cost of running constantly will outweigh the other benefits even if your app is the only one doing it. If every app is trying to run continuously to do the same kind of monitoring, the user's experience is going to be terrible.

The closest you can come in a reasonable way by yourself is to run a service "occasionally" to check the constraints you're interested in, and back off and retry later if they don't hold at the time you check. You need to be careful about how you're scheduling things, too -- in particular, if you're going to be using the network you need to be extremely careful that you are not accidentally causing lots of devices to hit the network at the same time. Cell carriers get very unhappy if they see simultaneous traffic from your app from every device on their network. Also, remember to avoid exact alarms if at all possible, so that the OS has leeway to batch your app's work together with others'.

Device-idle / user activity is hard for your app to track by itself, unfortunately, but connectivity and charge state are readily available.

A final tool at your disposal is the Sync Manager, which requires more infrastructure to use but does offer some reasonably powerful scheduling facilities, especially around connectivity requirements.

like image 31
ctate Avatar answered Oct 27 '22 15:10

ctate