I am developing an app in Android that performs a background sync with a server (using SyncAdapter and authentication etc).
When the foreground app (with UI) is started, there maybe a background sync in progress, or optionally it may start one via a UI button.
I would like a way to “plug into” an on-going background sync (whether started by the system, or the periodic sync setting or the UI) and show it’s progress in the foreground activity.
The ContentResolver documentation (http://developer.android.com/reference/android/content/ContentResolver.html) mentions a mysterious “SyncObserver” that has no link to javadoc and is not documented (that I can find).
There are some other pages around that mention it (http://www.chinaup.org/docs/migrating/m5-0.9/changes/android.content.ContentResolver.html) but I can’t find out more about it.
Has anyone implemented this beast?
If not, does anyone have example code or recommendations on tracking the progress of a background sync in a foreground Activity?
I had this same problem and ended up implementing it with a combination of 1) a broadcast from the SyncAdapter, and 2) using SharedPreferences to indicate status.
In the SyncAdapter, something like this this:
In the activity we do two things at resume 1) check the shared preference for whether a sync is currently in progress, 2) register to listen for broadcasts with a receiver.
This seems to work for me. I must admit I have a feeling that there are some potential issues with this due to the asynchronous nature of the broadcasts. Any input on improving my approach would be appreciated!