Using Job Scheduler in Android API <21

There is a very nice and powerful job scheduler library from Evernote. It uses the best method on each SDK level and gives you one very clean and elegant interface to schedule and run jobs.


from now on (after I/O 2015), you can also use new GcmNetworkManager. How to use it and how it works is described here - https://developers.google.com/cloud-messaging/network-manager

It does a lot cool stuff like it persists your tasks trough reboots. On Lolipop it uses JobScheduler, on pre-Lolipop it uses it's own implementation.

EDIT:

An example code on how to use it : https://github.com/jacktech24/gcmnetworkmanager-android-example


There are a few methods of running "jobs" pre-lollipop.

As mentioned you can use the JobSchedulerCompat library, but this library has a huge difference compared to the default Lollipop API:

On Lollipop jobs are batched and scheduled for all apps at once. The library however does not have access to other apps data and therefore can't combine jobs from two different apps using the library.

Another option you might want to try is the AlarmManager API. This API can be used for scheduling jobs, but the one difference is that the AlarmManager does not have constraints other than timing for running jobs.

Since KitKat the AlarmManager API also batches jobs when not scheduled with the "exact" methods. Before KitKat jobs are not batched.

If your goal is to sync data, than the Sync-Adapter API might be useful: Sync-Adapter

References: AlarmManager, JobSchedulerCompat


The recommended approach for pre-lollipop devices is to use the https://github.com/firebase/firebase-jobdispatcher-android#user-content-firebase-jobdispatcher-

Read more on https://developer.android.com/topic/performance/scheduling.html#fjd

Firebase JobDispatcher is an open-source library that provides an API similar to JobScheduler in the Android platform. Firebase JobDispatcher serves as a JobScheduler-compatibility layer for apps targeting versions of Android lower than 5.0 (API level 21).

Firebase JobDispatcher supports the use of Google Play services as an implementation for dispatching (running) jobs, but the library also allows you to define and use other implementations: For example, you might decide to use JobScheduler or write your own, custom code. Because of this versatility, we recommend that you use this Firebase JobDispatcher if your app targets a version of Android lower than 5.0 (API level 21).

For more information about Firebase JobDispatcher, refer to its documentation and source code.