Search code examples
androidcursorandroid-contentproviderandroid-loadermanager

Do Query Parameters affect ContentResolver notifyChange


I am using a query parameter to my ContentProvider that allows me to inform it when the request is coming from the Sync Adapter, so that it can do things like make sure to not trigger a sync to network. I'm using a CursorLoader with the LoaderManager to attach a Cursor to a CursorAdapter in a ListView - the basics. The database that is being provided gets updated through the Sync Adapter, so notifications will be using the URI that the Sync Adapter uses (the one with the attached query parameter). When I let the Sync Adapter finish before I reset the loader I get the appropriate data in the ListView, but if I try to reset the loader while some of the data is still being synced I get what was in the database at that time and not notified to reset when the data has finished downloading.

I haven't found any answers to if query parameters affect who gets notified with ContentResolver.notifyChange(Uri, ContentObserver, boolean). So I'm trying to tackle the issue, but if someone can answer that question before I figure it out it would be much appreciated. To be clear, my ContentProvider is calling cursor.setNotificationUri(getContext().getContentResolver(), uri) when the requester wasn't the Sync Adapter in ContentProvider.query(...). And it calls getContext().getContentResolver().notifyChange(uri, null, false) when the requester is the Sync Adapter in ContentProvider.insert/update/delete/bulkInsert(...) using the URI that triggered the request.


Solution

  • The answer appears to be "no, query parameters to not seem to be included in the specification of which URIs get notified on a notifyChange(...) call, or rather the ContentObserver is registering itself automatically to receive all descendant URI notifications as well."

    My issue appears to be that I was unintentionally still using the SimpleCursorLoader that was implemented in a different question for providing a CursorLoader implementation that doesn't rely on a ContentProvider. I'm now using a ContentProvider, so I changed to the default CursorLoader and that appears to have resolved the issue.