A customer takes a photo of a receipt, taps submit and puts the phone away. Whether that photo reaches your servers depends on code nobody demos: the part that runs after the screen is gone. When it fails there is no error message, because there is no screen to show one on.
What the Platform Actually Promises
Android stops background activity to protect the battery, so Google provides one sanctioned tool for work that must complete. Its promise is specific: it "features a robust scheduling mechanism that lets tasks persist across app restarts and device reboots" (Android).
The same documentation is just as specific about the limits. "WorkManager is not intended for in-process background work that can safely be terminated if the app process goes away. It is also not a general solution for all work that requires immediate execution." Guaranteed is not the same as immediate, and a product requirement that needs both needs a different design.
Three Numbers Worth Knowing
Scheduling has hard floors that no amount of engineering removes. "The minimum repeat interval that can be defined is 15 minutes" (Android). A failed job waits before it retries, and "The default policy is EXPONENTIAL with a delay of 30 seconds". A promise of sync every minute cannot be kept with this tool.
The Job Can Be Stopped Halfway
Conditions such as "only on Wi-Fi" are not checked once. "In the event that a constraint becomes unmet while your work is running, WorkManager will stop your worker. The work will then be retried when all the constraints are met." Work that cannot survive being stopped and started again will eventually corrupt something.
Our own article on this had two statements its sources did not support, including a claim about what happens when a user force-stops the app. Both were corrected this month.
What to Ask Your Team
- Which user actions depend on background work finishing? List them. Each is a silent failure mode.
- What happens if a job is stopped halfway and run again? The answer should be nothing.
- Do we retry forever, or stop and tell someone? Both are wrong as defaults.
- Does any requirement assume sync faster than every 15 minutes?
-Rocky
#MobileReliability #BackgroundWork #Android #EngineeringDreams #StrategiaX
Originally published on ANDROID-ARCHITECT, the Android engineering blog of Strategia-X, with the worker code and the corrected samples.
