【问题标题】:Why doesn't the notification URI work for a MergeCursor?为什么通知 URI 不适用于 MergeCursor?
【发布时间】:2013-03-09 15:07:43
【问题描述】:

假设您在 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 上不起作用,那么请分享您的知识。

【问题讨论】:

标签: android android-contentprovider android-contentresolver android-cursor android-cursorloader


【解决方案1】:

因此,您需要在生成的MergeCursor 中为Cursor 设置通知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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    相关资源
    最近更新 更多