0

I recently learned that when using a ContentProvider with CursorLoaders, there is no need to create your own ContentObserver, you just call cursor#setNotificationUri() or getContext().getResolver().notifyChange. Now i want to use a SyncAdapter to perform syncs on data change, and a requirement for this is having a ContentObserver for the respective URIs, my question is, what effect will this have on the aforementioned way of listening for data changes?

lll
  • 173
  • 15

1 Answers1

1

You don't need a ContentObserver to trigger a sync when using a SyncAdapter. Just make sure you set syncToNetwork to true when you call notifyChange (Uri uri, ContentObserver observer, boolean syncToNetwork).

Android will automatically call all SyncAdapters for this authority that have supportsUploading set to true and that are configured to sync automatically.

Marten
  • 3,802
  • 1
  • 17
  • 26
  • but the cursor.setNotificationUri method doesnt have the syncToNetwork parameter, what do i do in that case? – lll May 31 '16 at 19:25
  • That's irrelevant. That is only to notify the cursor about changes, so the UI can update itself immediately. Your ContentProvider should set `syncToNetwork` to `true` whenever something has been changed that might need to be synced (so you only need to set it on insert, update and delete operations). Be aware that you should not set it to true when something has been changed by the SyncAdapter (as this might cause a loop). – Marten May 31 '16 at 19:56