Introduction: Android library to schedule background jobs using JobScheduler, GCMNetworkManager or AlarmManager, depending on the context.
More: Author   ReportBugs   

JobSchedulerCompat is a backport of JobScheduler for API 16 and above. Depending on the context, it will use:


The API follows JobScheduler's very closely:

PersistableBundle extras = new PersistableBundle();
extras.putString("key", "value");

JobInfo.Builder builder =
    new JobInfo.Builder(0, new ComponentName(context, MyJobService.class))


This is how MyJobService could look like:

public class MyJobService extends JobService {
    public boolean onStartJob(JobParameters params) {
        // Spawn a thread to execute your logic.
        return false;

    public boolean onStopJob(JobParameters params) {
        // Stop executing this job.
        return false;

As all regular services, it needs to be declared in your AndroidManifest.xml:

<service android:name=".MyJobService" />

All necessary components have compatibility variants and follow their counterparts' APIs, with a few limitations:

Component Modeled after Limitations
JobScheduler JobScheduler None.
JobInfo JobInfo JobInfo.TriggerContentUri and related APIs:
JobInfo#getFlexMillis()) and related APIs:
JobService JobService None.
JobParameters JobParameters JobParameters#getTriggeredContentUris()) and related APIs:
PersistableBundle PersistableBundle None.


We wanted a library that offered the core functionality of JobScheduler all the way back to API 16. We wanted it to handle its context gracefully using the best engine available. We wanted it to not have a hard dependency on Google Play Services. We wanted its API to follow JobScheduler's API closely, so that it can be easily swapped by changing a few import statements.

We looked at the status quo:

Library Minimum SDK Requires Google Play Services Uses best job scheduling engine for context Same API as JobScheduler
Framework's JobScheduler 21 No. Yes. Yes.
Firebase JobDispatcher 9 Yes. No. Similar.
Evernote's Android-Job 14 No. Yes. No.

While all these libraries are phenomenal, neither met all our requirements, so we built one. Its minimum SDK is 16, it doesn't require Google Play Services, it uses the best job scheduling engine depending on the context, and its API mimics JobScheduler's.


Copyright 2016 Google, Inc.
Copyright 2017 Doist

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
Android 开发经验分享
Android 开发经验分享