1 year ago

#372783

test-img

Alexey Kolosov

How to get the remaining time after which worker will do work?

I schedule one time work in 100 minutes:

val request = OneTimeWorkRequestBuilder<MyWorker().setInitialDelay(100, TimeUnit.MINUTES).build()
WorkManager.getInstance(context).enqueueUniqueWork(
    "MY_WORKER_NAME",
    ExistingWorkPolicy.REPLACE,
    request
)

class MyWorker(context: Context, workerParameters: WorkerParameters) : CoroutineWorker(
    context, workerParameters) {
    override suspend fun doWork(): Result {
       return Result.success()
}

How can I get the remaining time, before doWork() is executed? For example, I need to know it immediately after I reboot my Android device

android

kotlin-coroutines

androidx

android-workmanager

0 Answers

Your Answer

Accepted video resources