Question

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.

Was it helpful?

Solution

I don't know the real reason behind it, but I managed to get it working.

The problem was that I was trying to send URI as a parcelable extra. When I sent it via ContentObserver it just silently failed to send it to the SyncAdapter. But when I tried the same call from my Activity it resulted in some exception (don't really remember what it was).

The solution was to just get rid of this extra and to send some constant integer instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top