Register now for Android Dev Summit 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

abstract suspend ListenableWorker.Result

A suspending method to do your work.

Unit

ListenableFuture<ListenableWorker.Result>

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

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

startWork

fun startWork(): ListenableFuture<ListenableWorker.Result>

Properties

coroutineContext

open val coroutineContext: CoroutineDispatcher

Deprecated.

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