PeriodicWorkRequest not repeating on the tick
Asked Answered
D

1

5

Im setting PeriodicWorkRequest for 15 minutes. But its repeating sometimes 10 sometimes 17 minutes. How can I set max a few seconds deviation.

 val workRequest = PeriodicWorkRequest.Builder(NotificationWork::class.java, 15, TimeUnit.MINUTES).build()
        WorkManager.getInstance().enqueue(workRequest)

13:10

13:26

13:51

14:01

Can I set a background work like an alarm on the tick or else Workmanager work like this always?

My code block is like above.

Disunity answered 14/1, 2019 at 13:3 Comment(4)
Precise scheduling is energy-inefficient, that's why Android won't let you have it.Longterm
Then I have to use AlarmManager for punctual work like alarm app? @MarkoTopolnikDisunity
Maybe you succeed with that, but the inaccuracy is there for a reason. Your app may get flagged as a battery drainer.Longterm
Do you have it on active app kept in background only? How about killed app? It doesn't work for me at all if the app is killed.Divider
E
6

As Marko said, Precise scheduling is battery in-efficient. WorkManager APIs don't guarentee schedule for that very reason. If you want strict timing, you can take a look at the AlarmManager APIs for that.

Enright answered 14/1, 2019 at 20:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.