Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
val repeatedReq = PeriodicWorkRequest.Builder(
MyWorkerClass::class.java,15,TimeUnit.MINUTES).build()
WorkManager.getInstance(this).enqueue(repeatedReq)
My WorkManager is calling doWork every 3-6 minutes rather than every 15 minutes like I specified in my code. Does anyone know why? Thanks.
As pointed by @Kasim, PeriodicWorkRequest
has a minimum interval of 15min. if you want to have a unique instance of your request you should use:
val repeatedReq = PeriodicWorkRequest.Builder(MyWorkerClass::class.java,15,TimeUnit.MINUTES).build()
WorkManager.getInstance(this).enqueueUniquePeriodicWork("YOURUNIQUENAME", ExistingPeriodicWorkPolicy.KEEP, repeatedReq)
ExistingPeriodicWorkPolicy.KEEP
: If there is existing pending (uncompleted) work with the same unique name, do nothing. Otherwise, insert the newly-specified work.
ExistingPeriodicWorkPolicy.REPLACE
: If there is existing pending (uncompleted) work with the same unique name, cancel and delete it. Then, insert the newly-specified work.
Periodic work has a minimum interval of 15 minutes.
If it runs every 3-6 minutes, you have many workManagers. You forgot
to cancel the others
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.