By referring to: Android WorkManager api for running daily task in Background
It uses the WorkManager.enqueueUniquePeriodicWork
to ensure that PeriodicWorkRequest is not created multiple times.
example code:
val work = PeriodicWorkRequestBuilder<SyncWork>(15,TimeUnit.MINUTES).build()
WorkManager.getInstance().enqueueUniquePeriodicWork("TaskTag",
ExistingPeriodicWorkPolicy.KEEP, work);
However, I found it there is 2 option of ExistingPeriodicWorkPolicy
which is ExistingPeriodicWorkPolicy.KEEP
and ExistingPeriodicWorkPolicy.REPLACE
can be use.
I try to implement it and run the code, but it does really show any differences, and it seem both of them behave the same way.
My uncertainty:
How does the ExistingPeriodicWorkPolicy.KEEP
perform differently from ExistingPeriodicWorkPolicy.REPLACE
?