Skip to content

Instantly share code, notes, and snippets.

@ceruleanotter
Last active June 25, 2022 14:26
Show Gist options
  • Save ceruleanotter/300c8fd4a569f5b21921e74d14e3b35d to your computer and use it in GitHub Desktop.
Save ceruleanotter/300c8fd4a569f5b21921e74d14e3b35d to your computer and use it in GitHub Desktop.
WorkManager Basics: WorkStatus Observation
// In your UI (activity, fragment, etc)
WorkManager.getInstance().getWorkInfoByIdLiveData(uploadWorkRequest.id)
.observe(lifecycleOwner, Observer { workInfo ->
// Check if the current work's state is "successfully finished"
if (workInfo != null && workInfo.state == WorkInfo.State.SUCCEEDED) {
displayImage(workInfo.outputData.getString(KEY_IMAGE_URI))
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment