val request = PeriodicWorkRequestBuilder<FooWorker>(1, TimeUnit.DAYS).build()
WorkManager.getInstance().enqueueUniquePeriodicWork(
"FOO",
ExistingPeriodicWorkPolicy.REPLACE,
request
)
The code above is ran in onCreate
of Application
to ensure the request is enqueued. However, this will cause a problem where the FooWorker
will run every time user start the application because ExistingPeriodicWorkPolicy.REPLACE
cancel previous work and enqueue new work which cause it run immediately.
If we change to ExistingPeriodicWorkPolicy.KEEP
, we will not able to replace the work even the period or the worker is changed.
Is there a way to replace the request after the current one is running?
For example, origin request run a 1 time per day and the new request is 1 time per hour. After the next origin request is ran, then replace it with new request.