I use the WorkManager version 2.2.0 to start a Coroutines API Call when the user gets online again.
In the example by Google, if I want to change the Thread of my CoroutineWorker from the default (Dispatchers.Default
) to Dispatchers.IO
, then I simply have to override the val
coroutineContext
such as:
class CoroutineDownloadWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
override val coroutineContext = Dispatchers.IO
override suspend fun doWork(): Result = coroutineScope {
// do some work here and return a Result
}
}
But Android Studio and the Docs tell me, that overriding coroutineContext
is deprecated:
What am I missing and how can I resolve this issue?
go to the desired coroutineContext in the body of the suspending function
? – Borodin