Last active
June 25, 2022 06:41
-
-
Save ceruleanotter/df10e1ac78661ff47893770d1bd4539c to your computer and use it in GitHub Desktop.
WorkManager Basics: Complete WorkRequest Example
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
// Create the Constraints | |
val constraints = Constraints.Builder() | |
.setRequiredNetworkType(NetworkType.CONNECTED) | |
.build() | |
// Define the input | |
val imageData = workDataOf(Constants.KEY_IMAGE_URI to imageUriString) | |
// Bring it all together by creating the WorkRequest; this also sets the back off criteria | |
val uploadWorkRequest = OneTimeWorkRequestBuilder<UploadWorker>() | |
.setInputData(imageData) | |
.setConstraints(constraints) | |
.setBackoffCriteria( | |
BackoffPolicy.LINEAR, | |
OneTimeWorkRequest.MIN_BACKOFF_MILLIS, | |
TimeUnit.MILLISECONDS) | |
.build() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment