Created
October 21, 2018 06:58
-
-
Save paulfranco/0bc446fed25367398f3b7a1bd086faab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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