public abstract class CoroutineWorker extends ListenableWorker

   ↳ ListenableWorker
     ↳ CoroutineWorker

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

By default, CoroutineWorker runs on [Dispatchers.Default]; this can be modified by overriding [coroutineContext].

A CoroutineWorker is given a maximum of ten minutes to finish its execution and return a [ListenableWorker.Result]. After this time has expired, the worker will be signalled to stop.


Public fields

@NonNull CoroutineDispatcher

This field is deprecated. use withContext(...) inside doWork() instead.

Public constructors

Public methods

abstract @NonNull ListenableWorker.Result

A suspending method to do your work.

@NonNull ForegroundInfo
final @NonNull ListenableFuture<@NonNull ForegroundInfo>

Return an instance of ForegroundInfo if the WorkRequest is important to the user.

final void

This method is invoked when this Worker has been told to stop.

final void
setForeground(ForegroundInfo foregroundInfo)

Makes the CoroutineWorker run in the context of a foreground

final void

Updates the progress for the CoroutineWorker.

final @NonNull ListenableFuture<@NonNull ListenableWorker.Result>

Override this method to start your actual background processing.

Inherited methods

From class ListenableWorker
final @NonNull Context
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) @NonNull Executor
final @NonNull UUID