Created
September 6, 2020 11:41
-
-
Save LaszloLajosT/56041187f6e7a633ce34b568fbd2790b to your computer and use it in GitHub Desktop.
FirebaseJobDispatcher Sample Code:
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
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