Md Sohail
03/01/2024, 3:13 AMprivate 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?Stefan Oltmann
03/01/2024, 6:22 AMMd Sohail
03/02/2024, 6:04 AMStefan Oltmann
03/02/2024, 6:44 AM