Background Delivery
Background delivery ensures that data updates are sent to your backend via webhooks, even when the application is in the background or closed.
Important notes about background delivery on Android
- Background delivery is scheduled to run every hour, but ultimately Android decides when the delivery will be executed.
- Android may throttle the frequency of updates for background delivery depending on the app’s activity, battery state, etc.
- Android may stop background delivery if it detects that the app is not active for a long time.
- There is a limit of queries that can be done in Health Connect and it is different for foreground and background reads, so please request only essential data to be delivered in background. More information on (Health Connect documentation)
Setup
Add the following permission to your AndroidManifest.xml:
Check if background delivery is possible with current Health Connect version:
If not, you can ask user to update Health Connect to the latest version.
Ask for background read permission:
You can also ask for background delivery permission in the same time as other permissions.
Now you can enable background delivery:
Keep in mind that calling enableBackgroundDeliverywill overwrite previous configuration. If you want to add more types, you have to call enableBackgroundDeliveryagain with updated configuration:
To check current configuration call getBackgroundDeliveryConfig() method.
To stop background delivery call disableBackgroundDelivery() method.