Skip to content

Instantly share code, notes, and snippets.

@aruke
Created March 10, 2019 14:30
Show Gist options
  • Save aruke/c41016b11247b2a1227c051ac7f4e264 to your computer and use it in GitHub Desktop.
Save aruke/c41016b11247b2a1227c051ac7f4e264 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.
class SimpleWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
private val delayInSeconds: Int = workerParams.inputData.getInt(KEY_DELAY, 0)
override fun doWork(): Result {
// Do intensive task here
// For now, our old friend Thread.sleep can replace intensive task here.
Thread.sleep(delayInSeconds * 1000L)
// Return with success
return Result.success()
}
companion object {
const val KEY_DELAY = "com.quipper.wmdemo.DELAY"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment