CursorLoader does not update after notification

I registered CursorLoaderbut not receiving updates from myContentProvider

Sequence of events:

  • In a Fragmentregister CursorLoader with:

    getLoaderManager().initLoader(LOADER_FAVS_ID, null, this);
    

    Note. I am using the support library version, so this methodandroid.support.v4.app.Fragment.getLoaderManager()

  • It is registered CursorLoader, and Cursorloaded into onLoadFinished:

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            Log.i(TAG, "onLoadFinished");
            switch (loader.getId()) {
            case LOADER_FAVS_ID:
                    Log.i(TAG,
                                    "cursor notification uri: " + cursor.getNotificationUri());
                    mCursorAdapter.swapCursor(cursor);
                    break;
            }
    }
    

    What magazines cursor notification uri: content://com.myapp.mylocation/db_locations, for example. This is because I definitely called cursor.setNotificationUri(getContext().getContentResolver(), uri);before returning the cursor from my ContentProvider. Also note that my content provider is returning MergeCursor.

  • After some time, the call is made to update()in mine ContentProvider, and the following lines are executed:

    Log.i(TAG,
            "Notifying uri: " + uri.toString());
    getContext().getContentResolver().notifyChange(
            uri, null);
    

    Which logs Notifying loc uri: content://com.myapp.mylocation/db_locationsare the same uri as above.

onLoadFinished , Cursor . , , , . onLoadFinished ?

+4
1

, , .

MergeCursor ContentProvider, .

    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
            // Generate an array of Cursors

            MergeCursor mergCursor = new MergeCursor(cursorArray);

            // notify potential listeners
            mergCursor.setNotificationUri(getContext().getContentResolver(), uri);

            return mergCursor;
    }

CursorLoader . , MergeCursor Cursor, uri MergeCursor.

    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
            // Generate an array of Cursors

            // set the notification uris...
            for (Cursor cursor : cursorArray) {
                    cursor.setNotificationUri(getContext().getContentResolver(), uri);
            }

            MergeCursor mergCursor = new MergeCursor(cursorArray);

            return mergCursor;
    }

, !

+5

All Articles