kikinteractive/firebase-jobdispatcher-android

Name: firebase-jobdispatcher-android

Owner: Kik Interactive

Description: null

Forked from: firebase/firebase-jobdispatcher-android

Created: 2016-07-09 19:44:51.0

Updated: 2017-05-21 16:52:20.0

Pushed: 2016-10-18 21:06:00.0

Homepage: null

Size: 198

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Firebase JobDispatcher Build Status

The Firebase Android JobDispatcher is a library that provides a high-level wrapper around job scheduling engines on Android, starting with the GCM Network Manager.

This replaces the old GCM Network Manager library.

Installation

For now, clone the repo:

clone https://github.com/firebase/firebase-jobdispatcher-android
irebase-jobdispatcher-android

Build the aar bundle:

adlew aar

And copy it to where you need it:

obdispatcher/build/outputs/aar/jobdispatcher-release.aar
Concepts
Job

A Job is a description of a unit of work. At its heart, it's composed of a series of mandatory attributes:

As well as a set of optional attributes:

Driver

Driver is an interface that represents a component that can schedule, cancel, and execute Jobs. The only bundled Driver is the GooglePlayDriver, which relies on the scheduler built-in to Google Play services.

Trigger

A Trigger is a “sticky” condition. When a Trigger is activated (or “triggered”) it remains triggered until its associated Job is successfully executed.

There are two currently supported Triggers:

Constraints

Constraints are runtime conditions that need to be met in order to run the Job.

There are three currently supported constraints:

Usage

All access to Jobs is handled through a root FirebaseJobDispatcher object, which wraps a Driver. You can create an instance that uses the Google Play driver like so:

er myDriver = new GooglePlayDriver(myContext);
baseJobDispatcher dispatcher = new FirebaseJobDispatcher(myDriver);

Usually you'll want to create a single FirebaseJobDispatcher instance that can be shared throughout your app.

All Jobs are represented by subclasses of com.firebase.jobdispatcher.JobService, which exposes the same end-user API as the Android framework's JobService class. A direct example might look like so:

ic class MyJobService extends JobService {
private AsyncTask asyncTask;

@Override
public boolean onStartJob(JobParameters job) {
    // Begin some async work
    asyncTask = new AsyncTask<Object, Object, Object>() {
        protected Object doInBackground(Object... objects) {
            /* do some work */
        }

        protected void onPostExecute(Object result) {
            jobFinished(job, false /* no need to reschedule, we're done */);
        }
    };

    asyncTask.execute();

    return true; /* Still doing work */
}

@Override
public boolean onStopJob(JobParameters job) {
    asyncTask.cancel();

    return true; /* we're not done, please reschedule */
}

Just like any other Service, you'll need to register your subclass in your AndroidManifest.xml. For security reasons it should not be exported. Make sure you include the <intent-filter> as follows:

vice android:name=".MyJobService" android:exported="false">
ntent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
intent-filter>
rvice>

Finally, you can create and schedule your Job:

job = dispatcher.newJobBuilder()
.setService(MyJobService.class)
.setTag("my-tag")
.setConstraints(
    Constraint.DEVICE_CHARGING,
    Constraint.ON_UNMETERED_NETWORK)
.setTrigger(Trigger.NOW)
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setRecurring(false)
.build();

result = dispatcher.schedule(job);
result != FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS) {
// handle error

For more usage examples, see the JobFormActivity class in the included testapp.

Contributing

See the CONTRIBUTING.md file.

Support

This library is actively supported by Google engineers. If you encounter any problems, please create an issue in our tracker.

License

Apache, see the LICENSE file.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.