Skip to content

Instantly share code, notes, and snippets.

@LaszloLajosT
Created September 6, 2020 11:41
Show Gist options
  • Save LaszloLajosT/56041187f6e7a633ce34b568fbd2790b to your computer and use it in GitHub Desktop.
Save LaszloLajosT/56041187f6e7a633ce34b568fbd2790b to your computer and use it in GitHub Desktop.
FirebaseJobDispatcher Sample Code:
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();
@LaszloLajosT
Copy link
Author

LaszloLajosT commented Sep 6, 2020

For more information, check out the FirebaseJobDispatcher README. This also includes more sample code.

Attention :

WorkManager is now the preferred way to schedule jobs for Android apps. You can learn more about how to use WorkManager in this course Developing Android Apps with Kotlin. ( Or Migrating from Firebase JobDispatcher to WorkManager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment