Skip to content

Instantly share code, notes, and snippets.

@paulfranco
Created October 21, 2018 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulfranco/0bc446fed25367398f3b7a1bd086faab to your computer and use it in GitHub Desktop.
Save paulfranco/0bc446fed25367398f3b7a1bd086faab to your computer and use it in GitHub Desktop.
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(MyJobService.class)
// uniquely identifies the job
.setTag("complex-job")
// one-off job
.setRecurring(false)
// don't persist past a device reboot
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
// start between 0 and 15 minutes (900 seconds)
.setTrigger(Trigger.executionWindow(0, 900))
// overwrite an existing job with the same tag
.setReplaceCurrent(true)
// 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
)
.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment