Question

I have read and read related Q&A and can't believe that if my custom ContentProvider does things like this:

insertUri = ContentUris.withAppendedId( Data2TableMetaData.CONTENT_URI, rowId)
// notify listeners
getContext().getContentResolver().notifyChange(insertUri, null);

... ContentObservers do not have a way to retrieve the rowId.

Is this really right? I think I must be missing something because this just doesn't seem nice.

Was it helpful?

Solution

you are right. The callback interface does not contain info on what changed, only that a change has happened. But generally developers are encouraged to use things like CursorLoaders which do all the heavy lifting for you. http://developer.android.com/reference/android/content/CursorLoader.html

However, now with the new Android 16 api it is possible to retrieve the URI of the row in the OnChange method.

OTHER TIPS

In api level 16, ContentObserver does receive the uri, which has the rowId. However, before that, for a situation when you are inserting a row but then only want to listen to that rowId, you can call ContentResolver.registerContentObserver right after inserting, once you know the rowId.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top