• This repository has been archived on 08/Apr/2020
  • Stars
    star
    1,796
  • Rank 25,643 (Top 0.6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DEPRECATED please see the README.md below for details.

Firebase JobDispatcher

Status: Archived

This repository has been archived and is no longer maintained.

status: inactive


Update: April 2019

Last year, we announced Android Jetpack WorkManager. WorkManager, the new job management system in Jetpack, incorporates the features of Firebase Job Dispatcher (FJD) and Android’s JobScheduler to provide a consistent job scheduling service back to api level 14 while leveraging JobScheduler on newer devices. WorkManager works with or without Google Play Services, which is something FJD cannot do. WorkManager was first released to alpha in May 2018 and then went thru extensive iteration and improvement based on developer feedback including 10 alphas; it moved to beta on Dec 19, 2018, and was released to stable on Mar 5, 2019. One thing the team has been discussing at some length is whether it would be better for developers in the long run if we create one holistic solution via WorkManager; where we can pool all of our efforts and also give developers a single unified recommended path?

After careful evaluation, the team has decided to focus all of our efforts on WorkManager and to deprecate Firebase Job Dispatcher. We have modified our plans in direct response to developer feedback in order to make this as easy for you as possible. We know that managing background work is a critical part of your app and these changes impact you. We want to support you through this migration as much as we can by giving you as much advance notice as possible to make these changes. Firebase Job Dispatcher will be archived in github in about 1 year, on Apr 7, 2020. Apps should migrate to WorkManager or an alternative job management system before this date.

We’ve created a detailed migration guide to assist you in the transition to WorkManager. After Apr 7, 2020, this github repository will be archived and support for FJD customer issues will stop. Additionally, FJD will stop working once your app starts targeting an Android version after Android Q.

We are continuing to invest in and add new features to WorkManager and welcome any feedback or feature requests.

The Firebase JobDispatcher is a library for scheduling background jobs in your Android app. It provides a JobScheduler-compatible API that works on all recent versions of Android (API level 14+) that have Google Play services installed.

Overview

What's a JobScheduler?

The JobScheduler is an Android system service available on API levels 21 (Lollipop)+. It provides an API for scheduling units of work (represented by JobService subclasses) that will be executed in your app's process.

Why is this better than background services and listening for system broadcasts?

Running apps in the background is expensive, which is especially harmful when they're not actively doing work that's important to the user. That problem is multiplied when those background services are listening for frequently sent broadcasts (android.net.conn.CONNECTIVITY_CHANGE and android.hardware.action.NEW_PICTURE are common examples). Even worse, there's no way of specifying prerequisites for these broadcasts. Listening for CONNECTIVITY_CHANGE broadcasts does not guarantee that the device has an active network connection, only that the connection was recently changed.

In recognition of these issues, the Android framework team created the JobScheduler. This provides developers a simple way of specifying runtime constraints on their jobs. Available constraints include network type, charging state, and idle state.

This library uses the scheduling engine inside Google Play services(formerly the GCM Network Manager component) to provide a backwards compatible (back to Gingerbread) JobScheduler-like API.

This I/O presentation has more information on why background services can be harmful and what you can do about them:

Android battery and memory optimizations

There's more information on upcoming changes to Android's approach to background services on the Android developer preview page.

Requirements

The FirebaseJobDispatcher currently relies on the scheduling component in Google Play services. Because of that, it won't work on environments without Google Play services installed.

Comparison to other libraries

Library Minimum API Requires Google Play Service API1 Custom retry strategies
Framework JobScheduler 21 No JobScheduler Yes
Firebase JobDispatcher 14 Yes JobScheduler Yes
evernote/android-job 14 No2 Custom Yes
Android WorkManager3 14 No2 Custom Yes

1 Refers to the methods that need to be implemented in the Service subclass.
2 Uses AlarmManager or JobScheduler to support API levels <= 21 if Google Play services is unavailable.
3 Currently in alpha phase, soon to graduate to beta.

Getting started

Installation

Add the following to your build.gradle's dependencies section:

implementation 'com.firebase:firebase-jobdispatcher:0.8.6'

Usage

Writing a new JobService

The simplest possible JobService:

import com.firebase.jobdispatcher.JobParameters;
import com.firebase.jobdispatcher.JobService;

public class MyJobService extends JobService {
    @Override
    public boolean onStartJob(JobParameters job) {
        // Do some work here

        return false; // Answers the question: "Is there still work going on?"
    }

    @Override
    public boolean onStopJob(JobParameters job) {
        return false; // Answers the question: "Should this job be retried?"
    }
}

Adding it to the manifest

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

Creating a Dispatcher

// Create a new dispatcher using the Google Play driver.
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));

Scheduling a simple job

Job myJob = dispatcher.newJobBuilder()
    .setService(MyJobService.class) // the JobService that will be called
    .setTag("my-unique-tag")        // uniquely identifies the job
    .build();

dispatcher.mustSchedule(myJob);

Scheduling a more complex job

Bundle myExtrasBundle = new Bundle();
myExtrasBundle.putString("some_key", "some_value");

Job myJob = dispatcher.newJobBuilder()
    // the JobService that will be called
    .setService(MyJobService.class)
    // uniquely identifies the job
    .setTag("my-unique-tag")
    // one-off job
    .setRecurring(false)
    // don't persist past a device reboot
    .setLifetime(Lifetime.UNTIL_NEXT_BOOT)
    // start between 0 and 60 seconds from now
    .setTrigger(Trigger.executionWindow(0, 60))
    // don't overwrite an existing job with the same tag
    .setReplaceCurrent(false)
    // retry with exponential backoff
    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
    // constraints that need to be satisfied for the job to run
    .setConstraints(
        // only run on an unmetered network
        Constraint.ON_UNMETERED_NETWORK,
        // only run when the device is charging
        Constraint.DEVICE_CHARGING
    )
    .setExtras(myExtrasBundle)
    .build();

dispatcher.mustSchedule(myJob);

Cancelling a job

dispatcher.cancel("my-unique-tag");

Cancelling all jobs

dispatcher.cancelAll();

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.

More Repositories

1

code-prettify

An embeddable script that makes source-code snippets in HTML prettier.
JavaScript
5,768
star
2

chromedeveditor

Chrome Dev Editor is a developer tool for building apps on the Chrome platform - Chrome Apps and Web Apps, in JavaScript or Dart. (NO LONGER IN ACTIVE DEVELOPMENT)
Dart
2,924
star
3

android-Camera2Basic

Migrated:
Java
2,863
star
4

android-ConstraintLayoutExamples

Migrated:
Java
2,571
star
5

vrview

Library for embedding immersive media into traditional websites.
JavaScript
1,709
star
6

tiger

Java
1,645
star
7

flipjs

A helper library for doing FLIP animations.
JavaScript
1,409
star
8

android-PictureInPicture

Migrated:
Java
1,393
star
9

android-FingerprintDialog

Migrated:
Java
1,375
star
10

observe-js

A library for observing Arrays, Objects and PathValues
JavaScript
1,357
star
11

PyDrive

Google Drive API Python wrapper library
Python
1,304
star
12

js-marker-clusterer

A marker clustering library for the Google Maps JavaScript API v3.
JavaScript
1,279
star
13

android-RuntimePermissions

This sample has been deprecated/archived. Check this repo for related samples:
Java
1,263
star
14

android-Camera2Video

Migrated:
Java
1,201
star
15

chromium-webview-samples

Useful examples for Developing apps with the Chromium based WebView
Java
1,173
star
16

androidtv-Leanback

Migrated:
Java
1,148
star
17

caja

Caja is a tool for safely embedding third party HTML, CSS and JavaScript in your website.
Java
1,126
star
18

android-ui-toolkit-demos

Migrated:
Java
1,118
star
19

android-ScreenCapture

Migrated:
Java
1,021
star
20

android-BluetoothChat

Migrated:
Java
986
star
21

android-BluetoothLeGatt

Migrated:
Java
911
star
22

sample-media-pwa

A sample video-on-demand media Progressive Web App
JavaScript
889
star
23

ChromeWebLab

The Chrome Web Lab for Makers, Hackers and everyone
JavaScript
877
star
24

big-rig

A proof-of-concept Performance Dashboard, CLI and Node module
CSS
857
star
25

android-instant-apps

Migrated:
Java
847
star
26

cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
JavaScript
827
star
27

guitar-tuner

A web-based guitar tuner
JavaScript
822
star
28

android-JobScheduler

This sample has been deprecated/archived. Check this repo for related samples:
Java
773
star
29

flashlight

A pluggable integration with ElasticSearch to provide advanced content searches in Firebase.
JavaScript
757
star
30

friendlypix

FriendlyPix is a cross-platform Firebase example app
726
star
31

voice-memos

A Progressive Web App for recording and playing back voice memos.
JavaScript
724
star
32

android-audio-high-performance

We now recommend you use the Oboe libraries:
C++
715
star
33

android-EmojiCompat

Migrated:
Java
707
star
34

android-RecyclerView

Migrated:
Java
675
star
35

ios-swift-chat-example

FireChat implemented in Swift!
Objective-C
673
star
36

leanback-showcase

Migrated:
Java
639
star
37

android-transition-examples

Migrated:
581
star
38

geofire

Realtime location queries with Firebase
569
star
39

drive-music-player

Fully client side Music Player for Google Drive
JavaScript
566
star
40

android-viewpager2

Migrated:
552
star
41

science-journal-ios

Use the sensors in your mobile devices to perform science experiments. Science doesn’t just happen in the classroom or lab—tools like Science Journal let you see how the world works with just your phone.
Swift
532
star
42

topeka

quiz app
HTML
532
star
43

android-PdfRendererBasic

Migrated:
Java
522
star
44

science-journal

Use the sensors in your mobile devices to perform science experiments. Science doesn’t just happen in the classroom or lab—tools like Science Journal let you see how the world works with just your phone.
Java
508
star
45

tango-examples-java

Example projects for Project Tango [deprecated] Java API
Java
500
star
46

AndroidChat

Demonstrates using the Firebase Android SDK to back a ListView.
Java
499
star
47

android-nearby

Migrated:
Java
494
star
48

android-play-places

Deprecated:
Java
479
star
49

tango-examples-unity

Project Tango [deprecated] UnitySDK Example Projects
C#
475
star
50

easygoogle

Simple wrapper library for Google APIs
Java
471
star
51

firefeed

JavaScript
461
star
52

android-dynamic-features

Migrated:
Kotlin
460
star
53

android-MediaBrowserService

This sample is deprecated.
Java
457
star
54

graphd

The Metaweb graph repository server
C
445
star
55

drive-zipextractor

Extract (decompress) ZIP files into Google Drive using the Google Drive API
JavaScript
435
star
56

android-AutofillFramework

Migrated:
Java
432
star
57

webplatform-samples

HTML5 Samples/Demos
430
star
58

cloud-functions-go

Unofficial Native Go Runtime for Google Cloud Functions
Go
427
star
59

android-unsplash

Deprecated:
424
star
60

android-MultiWindowPlayground

Migrated:
Java
418
star
61

appengine-flask-skeleton

A skeleton for creating Python applications using the Flask framework on App Engine
Python
416
star
62

angularfire-seed

Seed project for AngularFire apps
JavaScript
412
star
63

node-big-rig

A CLI version of Big Rig
JavaScript
410
star
64

firebase-dart

Dart wrapper for Firebase
Dart
409
star
65

android-Camera2Raw

Migrated:
Java
386
star
66

js-store-locator

A library for easily building store-locator-type applications using the Google Maps JavaScript API v3
JavaScript
380
star
67

ADBPlugin

Google Chrome Extension with ADB Daemon
C++
372
star
68

android-fit

Migrated:
Java
372
star
69

android-NotificationChannels

This sample has been deprecated/archived. Check this repo for related samples:
Java
369
star
70

appengine-php-wordpress-starter-project

Starter project for running WordPress on Google Cloud Platform
PHP
368
star
71

android-ActivitySceneTransitionBasic

Migrated:
368
star
72

android-text

Migrated:
Kotlin
363
star
73

android-XYZTouristAttractions

Migrated:
356
star
74

firebase-angular-starter-pack

A Firebase + AngularJS Starter Pack
JavaScript
348
star
75

android-OurStreets

Migrated:
345
star
76

tango-examples-c

JNI example projects for Project Tango [deprecated] C-API
C++
334
star
77

simian

Simian is an enterprise-class Mac OS X software deployment solution. Google App Engine hosted server, with a client powered by the Munki open-source project.
Python
334
star
78

OpenInChrome

Open in Chrome
Objective-C
333
star
79

android-DownloadableFonts

Migrated:
Java
319
star
80

friendlypix-web

FriendlyPix is a cross-platform Firebase example app - This is the web version
JavaScript
312
star
81

pywebsocket

WebSocket server and extension for Apache HTTP Server for testing
Python
310
star
82

android-DarkTheme

migrated:
Java
302
star
83

firereader

Firereader: A feed reader built with Firebase and AngularJS
JavaScript
301
star
84

android-WatchFace

Migrated:
300
star
85

android-MediaRecorder

Migrated:
Java
299
star
86

backbonefire

Backbone bindings for Firebase
JavaScript
291
star
87

TemplateBinding

TemplateBinding Prolyfill
JavaScript
291
star
88

firebase-login-demo-android

Java
280
star
89

Firebase-Unity

Objective-C
279
star
90

seed-element

Polymer element boilerplate
HTML
278
star
91

firebase-util

An experimental toolset for Firebase
JavaScript
276
star
92

android-NavigationDrawer

This sample has been deprecated/archived. Check this repo for related samples:
Java
276
star
93

android-DisplayingBitmaps

Migrated:
Java
272
star
94

wReader-app

RSS Reader written using AngularJS
JavaScript
271
star
95

gcm-playground

CSS
268
star
96

android-CardView

Migrated:
Java
265
star
97

soundstagevr

C#
263
star
98

ShadowDOM

ShadowDOM Polyfill
JavaScript
263
star
99

android-credentials

Migrated:
Java
260
star
100

gamebuilder

Game Builder is an application that allows users to create games with little or no coding experience.
C#
253
star