I have implemented a sync adapter and I want to get a callback when it finishes in my activity. I have tried using ContentResolver.addStatusChangeListener, but I am only get
One solution that I have found is to ditch the ContentResolver completely, and implement my own broadcast. Basically, add this in the sync adapter, at the end of onPerformSync:
Intent i = new Intent(SYNC_FINISHED);
sendBroadcast(i);
And this in the activity:
@Override
protected void onResume() {
super.onResume();
registerReceiver(syncFinishedReceiver, new IntentFilter(DataSyncService.SYNC_FINISHED));
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(syncFinishedReceiver);
}
private BroadcastReceiver syncFinishedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(Const.TAG, "Sync finished, should refresh nao!!");
}
};
This seems to work just fine, however I was hoping to find something in the SDK that directly notify me when a sync is finished.