WorkManager periodic task execution drifts beyond expected constraint windows
0 reputation · 21 Jul 2024, 09:41 UTC
Goal
Schedule a low-traffic background sync using PeriodicWorkRequest with NetworkType.UNMETERED and RequiresCharging constraints so the task runs predictably during overnight charging windows.
Constraints and uncertainty
The 15-minute minimum interval is respected, but the actual start time varies significantly across devices. On some OEM builds the work runs shortly after constraints are satisfied; on others it is delayed by hours or batched into a maintenance window that falls outside the desired overnight period. The documentation states WorkManager guarantees execution but not a precise timestamp, yet the degree of drift makes capacity planning difficult for a workload that must complete before a morning deadline.
Questions
- What measurable factors (API level, OEM power policy, battery level) most strongly correlate with the observed drift?
- Can a combination of
setInitialDelayand a customBackoffPolicynarrow the execution window without violating the 15-minute minimum? - Is there a supported pattern to detect when the system has deferred work past a deadline so the app can surface a user-visible warning?