SupportCoroutineWorker

abstract class SupportCoroutineWorker(context: Context, workerParameters: WorkerParameters) : CoroutineWorker

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

By default, CoroutineWorker runs on kotlinx.coroutines.Dispatchers.Default; this can be modified by wrapping the block of code in kotlinx.coroutines.withContext and providing the desired kotlinx.coroutines.Dispatchers

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

Since

v0.9.X

Constructors

Link copied to clipboard
constructor(context: Context, workerParameters: WorkerParameters)

Properties

Link copied to clipboard
open val coroutineContext: CoroutineDispatcher

Functions

Link copied to clipboard
abstract suspend override fun doWork(): ListenableWorker.Result

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

Link copied to clipboard
open suspend fun getForegroundInfo(): ForegroundInfo
Link copied to clipboard
override fun getForegroundInfoAsync(): ListenableFuture<ForegroundInfo>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@RequiresApi(value = 31)
fun getStopReason(): Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
override fun onStopped()
Link copied to clipboard
suspend fun setForeground(foregroundInfo: ForegroundInfo)
Link copied to clipboard
fun setForegroundAsync(@NonNull foregroundInfo: ForegroundInfo): ListenableFuture<Void>
Link copied to clipboard
suspend fun setProgress(data: Data)
Link copied to clipboard
open fun setProgressAsync(@NonNull data: Data): ListenableFuture<Void>
Link copied to clipboard
Link copied to clipboard
override fun startWork(): ListenableFuture<ListenableWorker.Result>
Link copied to clipboard