https://kotlinlang.org logo
#random
Title
# random
m

Md Sohail

03/01/2024, 3:13 AM
Copy code
private val uniqueWorkName = CountDownWorker::class._java_._simpleName_

@RequiresApi(Build.VERSION_CODES._O_)
fun enqueue(context: Context, force: Boolean = false) {
    val manager = WorkManager.getInstance(context)

    val requestBuilder = _PeriodicWorkRequestBuilder_<CountDownWorker>(30, TimeUnit._MINUTES_).build()

    var workPolicy = ExistingPeriodicWorkPolicy._KEEP_

    // Replace any enqueued work and expedite the request
    if (force) {
        workPolicy = ExistingPeriodicWorkPolicy._UPDATE_
    }

    manager.enqueueUniquePeriodicWork(
        uniqueWorkName,
        workPolicy,
        requestBuilder
    )
}
this is my code snippet, I want to schedule a work which updated the home widget after every 30 minutes. this works fine if the app is running in the foreground but if the app is closed for a long time, the widgets don't update, meaning the work manager doesn't work and it updates the widgets as soon as i open the app. So, can you guys please help me out? what should I do in this case?
s

Stefan Oltmann

03/01/2024, 6:22 AM
I assume you will find help in #android
m

Md Sohail

03/02/2024, 6:04 AM
I tried, but they marked it as Not Kotlin and said to ask it elsewhere
s

Stefan Oltmann

03/02/2024, 6:44 AM
Ok, I see. Yes, you might not find not help here then. You could as on StackOverflow or create a bug report on the Android issue tracker.