Skip to content

Instantly share code, notes, and snippets.

@ceruleanotter
Last active June 25, 2022 06:41
Show Gist options
  • Save ceruleanotter/df10e1ac78661ff47893770d1bd4539c to your computer and use it in GitHub Desktop.
Save ceruleanotter/df10e1ac78661ff47893770d1bd4539c to your computer and use it in GitHub Desktop.
WorkManager Basics: Complete WorkRequest Example
// 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