Suppose you have a CONTENT_URI
inside your ContentProvider
in which you want to do some complex stuff and return a combination of Cursors (MergeCursor
) instead of a simple, single Cursor
.
It so happens that if you set the notification URI
on the MergeCursor
instead of a cursor from within that MergeCursor
, the notification is not going to work.
Initial code:
Cursor[] cursors = { extraCursorBefore, usersCursor, extraCursorAfter };
Cursor extendedCursor = new MergeCursor(cursors);
// Make sure that potential listeners are getting notified
extendedCursor.setNotificationUri(getContext().getContentResolver(), CONTENT_URI_PEOPLE);
return extendedCursor;
PS: If by any means, somebody has another idea, or figures out why the hell this didn't work on the original MergeCursor
, then please, share your knowledge.
So you need to set the notification URI
on a Cursor
from within the resulting MergeCursor
.
Code that actually works:
Cursor[] cursors = { extraCursorBefore, usersCursor, extraCursorAfter };
Cursor extendedCursor = new MergeCursor(cursors);
// Make sure that potential listeners are getting notified
usersCursor.setNotificationUri(getContext().getContentResolver(), CONTENT_URI_PEOPLE);
return extendedCursor;