1

I am developing an Android app that i want to sync data with a server. For that i use the Android sync api and the SyncAdapter. Now when i request a manual sync my onPerformSync method in the sync adapter is called correctly. I have added all the points from this list: https://stackoverflow.com/a/5255360/3795043

However when i try to time a periodic sync, there is a messag in the log:

10-18 23:30:08.267 862-882/? W/SyncManager: Ignoring setPeriodicSyncTime request for a sync that does not exist. Authority: TwoRoomsSync/de.lehrbaum.tworooms.database:u0

Why is that the case? the sync obviously exists, otherwise requesting it manually would not work either, or? this is the code that sets up the sync:

final Account accountInstance = new Account(
       account, account_type);
// Get an instance of the Android account manager
AccountManager accountManager =
       (AccountManager) getSystemService(
                    ACCOUNT_SERVICE);
final boolean firstTime = accountManager.addAccountExplicitly(accountInstance, null, null);

if(firstTime) {
    //set sync enabled by default
    ContentResolver.setSyncAutomatically(accountInstance, authority, true);
    ContentResolver.addPeriodicSync(accountInstance, authority,
            Bundle.EMPTY, /* 5 hours interval */5 * 60 * 60);
    //request a sync
    final Bundle settingsBundle = new Bundle();
    settingsBundle.putBoolean(
            ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(accountInstance, authority, settingsBundle);
}
SyncAdapter.SYNC_OBSERVER = new ContentObserver(new Handler(getMainLooper())) {
    @Override
    public boolean deliverSelfNotifications() {
        return false;
    }
    @Override
    public void onChange(boolean selfChange) {
        Log.i(TAG, "On change for sync called. self change: " + selfChange);
        ContentResolver.requestSync(accountInstance, authority, Bundle.EMPTY);
    }
};
final ContentResolver resolver = getContentResolver();
Uri uri = Uri.withAppendedPath(CONTENT_URI, VOTES_TABLE);
resolver.registerContentObserver(uri, true, SyncAdapter.SYNC_OBSERVER);
uri = Uri.withAppendedPath(CONTENT_URI, SETS_TABLE);
resolver.registerContentObserver(uri, true, SyncAdapter.SYNC_OBSERVER);

Furthermore when i request a sync without adding the 'manual' flag, it does not work either. I don't know if the two issues are related.

Community
  • 1
  • 1
findusl
  • 2,454
  • 8
  • 32
  • 51

0 Answers0