I use a SyncAdapter to sync my data with the server. Everything works, but I have a hard time sending extras to SyncAdapter
.
In my ContentObserver
I use the following code to send request to SyncAdapter:
@Override
public void onChange(boolean selfChange, Uri changeUri) {
Bundle extras = new Bundle();
extras.putParcelable(Globals.EXTRA_URI, changeUri);
extras.putInt("no", 123456);
extras.putBoolean(
ContentResolver.SYNC_EXTRAS_MANUAL, true);
extras.putBoolean(
ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
ContentResolver.requestSync(account, MyProvider.AUTHORITY, extras);
}
However, on the SyncAdapter
side, I don't get these extras:
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
Uri changeUri = extras.getParcelable(Globals.EXTRA_URI);
int aaa = extras.getInt("no");
Log.i(TAG, "Syncadapter / uri: "+changeUri+"/"+aaa+"/"+extras.size());
//Logcat: Syncadapter / uri: null/0/1
...
}
I would like to use the extras to find out which piece of data needs to be synchronized. Also, the system ignores the ContentResolver specific extras: e.g. ContentResolver.SYNC_EXTRAS_MANUAL (the sync is not performed immediately)
EDIT:
I just noticed, that it's loosing those extra params only when called by ContentObserver.onChange(). When I call requestSync()
inside my Activity, everything works as expeceted.