I have a content observer that needs to be notified when one of the contacts added by my sync adapter changes. I register and unregister the observer doing this:
private static final Uri MYAPP_CONTENT_URI = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, SyncAdapter.MYAPP_ACCOUNT_NAME).appendQueryParameter(RawContacts.ACCOUNT_TYPE, MY_APP_ACCOUNT_TYPE).build(); public static void registerContentObserver() { ContentResolver resolver = MyApplication.getAppContext().getContentResolver(); cursorContacts = resolver.query(MYAPP_CONTENT_URI, null, RawContacts.DELETED + "=0", null, null); cursorContacts.registerContentObserver(MYAPP_URI_OBSERVER); } public static void unregisterContentObserver() { if (cursorContacts != null) { cursorContacts.unregisterContentObserver(MYAPP_URI_OBSERVER); cursorContacts.close(); } }
The problem is that even when the cursor is empty (getCount returns 0) after registering the observer, I get an onChange call, which I do in my own address book. Should you not call an observer only when one of the entries in the cursor has been changed? The documentation states:
Register an observer that is called when changes occur with content that supports this cursor.
What is content that supports this cursor? I thought this was a list of lookupuri contacts in the cursor, but it seems like this is enough to have changes in ContactsContract.RawContacts.CONTENT_URI.
I also tried to register one observer for each Uri. It does not help. Although the documentation for ContentResolver.registerContentObserver states:
Register an observer class that receives callbacks when the data identified by this content URI changes.
Parameters uri The URI to watch for changes. This can be a specific row URI, or a base URI for a whole class of content. notifyForDescendents If true changes to URIs beginning with uri will also cause notifications to be sent. If false only changes to the exact URI specified by uri will cause notifications to be sent. If true, than any URI values at or below the specified URI will also trigger a match.
(I set notifyForDescendents to false, but he shouldn't have called observers anyway).
What happened? thank you
source share