Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

CoroutineWorker

abstract class CoroutineWorker : ListenableWorker
kotlin.Any
   ↳ androidx.work.ListenableWorker
   ↳ androidx.work.CoroutineWorker

A ListenableWorker implementation that provides interop with Kotlin Coroutines. Override the doWork function to do your suspending work.

Summary

Public constructors
<init>(appContext: Context, params: WorkerParameters)

A ListenableWorker implementation that provides interop with Kotlin Coroutines.

Public methods
ListenableFuture<ListenableWorker.Result>

abstract suspend ListenableWorker.Result

A suspending method to do your work.

Unit

Inherited functions
Properties
open CoroutineDispatcher

The coroutine context on which doWork will run.

Public constructors

<init>

CoroutineWorker(appContext: Context, params: WorkerParameters)

A ListenableWorker implementation that provides interop with Kotlin Coroutines. Override the doWork function to do your suspending work.

Public methods

startWork

fun startWork(): ListenableFuture<ListenableWorker.Result>

doWork

abstract suspend fun doWork(): ListenableWorker.Result

A suspending method to do your work. This function runs on the coroutine context specified by coroutineContext.

Return
The ListenableWorker.Result of the result of the background work; note that dependent work will not execute if you return ListenableWorker.Result.failure

onStopped

fun onStopped(): Unit

Properties

coroutineContext

open val coroutineContext: CoroutineDispatcher

The coroutine context on which doWork will run. By default, this is Dispatchers.Default.