Triggering Android Sync Programmatically

I have sync working between Android and my PC, however I note that the phone only auto-syncs once the app has been opened.

I would like to be able to sync programmatically using Automate.

The use case for this is:

I use my phone to make entries when it is away from my PC, but these are not reflected on my PC until I re-open the Android app once I’m connected on my PC’s LAN. I want to avoid having to go to my phone to trigger a sync just so I can work on my PC.

I have tried launching the app via Automate when the phone is locked however this does not trigger a sync as I would have expected, so now I am wondering, can I do this via an (Android) Activity Class or some other way?

I have attached a few screenshots which shows what the Automate is capable of.

Hello Damian,

It’s not normal that sync only runs once.

Do you have the auto-sync setting enabled?
If you trigger sync manually repeatedly, does it work?
Which sync configuration are you using - local or sync service?

Hi Andrei,

Thanks for the quick response.

Just to clarify, I meant ‘once’ as in ‘when’, it was not a reference to a single occurrence.

  • I am using local sync
  • Auto-sync is enabled
  • Both auto-sync and manual sync work fine whenever I open the app on my phone

I would like the Android app to sync in the background, without me having to go into the app to trigger a sync. My issue is not that it doesn’t sync, but that any sync actions only occur when the app is open, is this normal?

Although I can programmatically open and close the app (with the phone locked and the screen off), this doesn’t trigger a sync.

As far as I understand, when the app is in the background, it is suspended by the operating system because of energy and memory management concerns. So sync cannot run reliably in the background.

As for triggering an activity directly, I haven’t tried that. There is auto sync logic in MainActivity, so if it’s allowed to run for a few seconds, then sync should take place.

Thanks Andrei.

I tried launching with MainActivity without any success. The app opens but doesn’t sync until I unlock my phone. Strange.

Another workaround might be to trigger a manual sync, unfortunately I can’t do this by manipulating the UI (swipe down), it would have to be done programmatically, if it’s actually possible.

The problem is that the app is not actually running until you unlock. Not sure how to solve this.

It seems there’s no easy way to implement this, but in any case, thanks Andrei for having taken the time to give it your consideration. If I stumble upon a solution I’ll be sure to post back here.

1 Like