Can the CHT sync data when the app is running in the background or the screen is off?

Is it currently possible for the CHT to sync data when the app is running in the background or the screen is off? Are there any technical limitations or design considerations behind this? Would love to understand the current behavior and whether background syncing is something that’s been explored. Thanks!

I think the answer here is no. Depending on what Android does when you background the app (or turn off the screen), the main process might remain running long enough to hit the 5min sync interval. However, that is more accidental than by design.

To support background syncing, I think we would need to leverage a proper background worker (like we did for notifications). However, as we found in that case, to do the sync, you really need the whole webapp running and that is not feasible in the background worker.

Another alternative (discussed during Android notifications) is a persistent notification that basically keeps the app running all the time (but that has all kinds of jankyness of its own since Android does not really like you doing that)…

Another option might be to leverage something like Firebase/UnifiedPush to actually wake up the app periodically.

This is an interesting problem to solve! @andra are you just curious or is there a real world scenario that is limited because CHT doesn’t support background sync?

This question comes from a community partner in the context of the Kenya deployment. They mentioned that CHPs would benefit from being able to sync data even when they’re not actively using the CHT — for instance, when they pass through an area with internet connectivity, syncing could happen automatically in the background without requiring them to open the app.

@alexkombo I believe you were part of that conversation. Would you have additional details or nuances to the need raised here?

It came up in response to observed user behavior. In practice, syncing tends to happen at the beginning or end of the month, even though connectivity may be available intermittently throughout.

Background sync would remove reliance on manual CHP-initiated syncs or foreground-only automatic sync. It would reduce the operational burden on CHPs and allow data to be available more consistently over the course of the month.