Created
March 10, 2019 14:30
-
-
Save aruke/33f90e45cc627e49e75a524c82643196 to your computer and use it in GitHub Desktop.
Gists to embed in WorkManager blog. Full code is available at https://github.com/aruke/WorkManagerDemo.
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
val workerId = simpleWorkRequest.id | |
WorkManager.getInstance().getWorkInfoByIdLiveData(workerId) | |
.observe(this, Observer<WorkInfo> { | |
it?.let { workInfo -> | |
when (workInfo.state) { | |
WorkInfo.State.ENQUEUED -> | |
Log.d(TAG, "Worker ENQUEUED") | |
WorkInfo.State.RUNNING -> | |
Log.d(TAG, "Worker RUNNING") | |
WorkInfo.State.SUCCEEDED -> | |
Log.d(TAG, "Worker SUCCEEDED") | |
WorkInfo.State.FAILED -> | |
Log.d(TAG, "Worker FAILED") | |
WorkInfo.State.BLOCKED -> | |
Log.d(TAG, "Worker BLOCKED") | |
WorkInfo.State.CANCELLED -> | |
Log.d(TAG, "Worker CANCELLED") | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment