ContactsProvider2 notification mechanism with base URI

19 views
Skip to first unread message

Ganesh Kumar

unread,
Sep 20, 2015, 9:06:45 AM9/20/15
to android-platform
I am referring ContactsProvider2 to implement my own contact provider. In this provider, there is one method notifyChanged() which is used to notify content observers in case of insert, update and delete.

protected void notifyChange(boolean syncToNetwork) {
        getContext().getContentResolver().notifyChange(ContactsContract.AUTHORITY_URI, null, syncToNetwork);
    }

Interestingly, this method uses the base URI for notification. Now if I adopt the same strategy in my provider where I have more than one table, I find that some unwanted notifications are fired. Here is the scenario where I am finding this.

I have 2 fragments each containing a list view. And I am using loaders to load list views. These list views are backed by 2 different tables table A and table B. Fragments are part of a view pager with a FragmentPagerAdapter. Now when I am in first fragment and add a record to table A, I observe that the loader in the second fragment also receives the call back on onLoadFinished().

This situation does not happen if I use more specific uri for notification. To be precise, for example, in case of delete() if I use the input uri for notification, the second fragment does not get call on onLoadFinished().

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    /*.....*/
    final int deletedRows = db.delete(getTableName(uri), appendedWhere, selectionArgs);
    if (deletedRows > 0) {
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return deletedRows;
}

Obviously, there is extra work if the base URI is used for notification. Now, the question is what is the exact reason for using base URI in notifyChange() method of ContactsProvider2? What are the advantages of this strategy?
Reply all
Reply to author
Forward
0 new messages