假设您的ContentProvider
中有一个CONTENT_URI
,您希望在其中执行一些复杂的操作,并返回一个组合的游标(MergeCursor
),而不是一个简单的Cursor
。
碰巧的是,如果您在MergeCursor
上设置通知URI
,而不是在该MergeCursor
中设置光标,则通知将无法工作。
初始代码:
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:如果有人以任何方式有了另一个想法,或者想知道为什么这个地狱不能在最初的MergeCursor
上工作,那么请分享你的知识。
发布于 2013-03-20 21:28:44
因此,您需要在Cursor
上从生成的MergeCursor
中设置通知URI
。
实际工作的代码:
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;
https://stackoverflow.com/questions/15524952
复制相似问题