Is it possible to run an Android Periodic and Onetime workers during Doze Mode or App Standby?

1k Views Asked by At

I have an app that uses both periodic and onetime workers to perform various tasks, some of which require a network connection. My client reported to me that a certain required daily task was not performed on a day he did not use the app at all. Despite the app's not having been run on a given day, the workers still need to run in order to report various statistics to the backend server. I assume this is due to the fact that the app was in App Standby Mode for the entire day, as well as the device's being in Doze Mode for at least part of the day. So my question is, is it possible to make a periodic or onetime worker run while the app is in App Standby or Doze Mode, or will it always be delayed until the device and/or app wakes up?

Alternatively, would I be better off using alarms instead of workers? I see that it is possible to set an alarm using setExactAndAllowWhileIdle() that "will be allowed to execute even when the system is in low-power idle modes." Does "idle mode" imply Doze and/or App standby mode?

I have been grappling with this for a while now, so any help and/or guidance is greatly appreciated.

1

There are 1 best solutions below

0
On

Work Manager is Deferrable background work when the work’s constraints are satisfied. if all the constraints set on a WorkRequest are satisfied, Work can still be run with some additional delay. It's because WorkManager respecting Android battery optimization strategies. Also, you can read more about WorkManager constraint to understanding the work's constraint here: https://developer.android.com/reference/androidx/work/Constraints.Builder.html