Reputation: 12416
In my app I have periodic task that needs to be executed periodically with high reliability.
Currently I am using WorkManager and observe that from time to time tasks execute way out of schedule.
The documentation vaguely mentions that api is "being conscious of battery life" and I think this might be the cause.
Anyway, I tried to disable "battery optimization" in application settings of my app and still observe delays I cannot tolerate in my app.
So, here is the question: what is the most reliable api I can use to schedule periodic (15-30 min) tasks and if there are some settings user might change to improve the reliability of tasks being executed on schedule?
Reliability is the main focus here, battery life can be sacrificed in my use case.
Ps: my main target is Android N, testing on Motorola Moto C.
Upvotes: 3
Views: 611
Reputation: 1508
There is nothing reliable. You are using Android. Every vendor does its own shit. Please check:
You "can" use push notifications, but it needs to be a high priority which means user interaction. If the user does not interact - soon you will be restricted. If you use low priority - your request is passed to the WorkManager - so you are back where you started from.
At least you can try to check the dump of the job scheduler and see what is restricting you.
Check:
Required constraints: TIMING_DELAY CONNECTIVITY [0x90000000]
Satisfied constraints: DEVICE_NOT_DOZING BACKGROUND_NOT_RESTRICTED WITHIN_QUOTA [0x3400000]
Unsatisfied constraints: TIMING_DELAY CONNECTIVITY [0x90000000]
You care about Unsatisfied constraints. Most are self-explanatory except - QUOTA which means that you were executed too many times in 24 hours. And CONNECTIVITY - besides not being with the right Network state, you also see this when you use too much Network in 24 hours. Please check here:
https://developer.android.com/topic/performance/power/power-details
Upvotes: 1