In my case I would like to call the composable from a OneTimeWorkRequest
.
As far as I'm aware composables are typically called from Activities with setContent()
. However I do not have access to this within the Worker
and not sure how to instantiate a 'blank/dummy' activity within the worker.
@Composable
fun Hello() {
Text(text = "Hello")
}
class MyWorker(private val appContext: Context, private val params: WorkerParameters)
: CoroutineWorker(appContext,params) {
override suspend fun doWork(): Result {
Hello() /*<---error here "@Composable invocations can only happen from the context of a @Composable function"*/
return Result.success()
}
}