Take the 2-minute tour ×

I am programming an app on Honeycomb and I am having trouble with Cursors from my content provider. I wish to achieve an effect that this simple code from the official Notepad example achieves:

Cursor note = mDbHelper.fetchNote(mRowId);

That is, I simply wish to put data from the current position of the Cursor into the EditText so the user can edit it. The problem is I have no idea how to do this with the CursorLoader. I can not use managedQuery() since it is deprecated and in any case I have to call startManagingCursor() which is also deprecated. How should I do this? Thanks in advance.

share|improve this question

2 Answers 2

Okay, I found the answer, which is rather obvious now. I simply used this piece of code:

String[] projection = { FlightBundleDatabase.ID, FlightBundleDatabase.COL_TITLE };
            String[] selectionArgs = { Long.toString(id) };

        CursorLoader cursorLoader = new CursorLoader(this, FlightBundleProvider.CONTENT_URI_PHASES, projection, "_id = ?", selectionArgs, null);
        Cursor cursor = cursorLoader.loadInBackground();

        if (cursor.moveToFirst()) {

Now I just hope the cursor does not leak any resources, but close() should take care of that, right?

share|improve this answer

Instead of:

Cursor cursor = loader.loadInBackground();

you can get a cursor directly:

Cursor cursor = this.getContentResolver().query(FlightBundleProvider.CONTENT_URI_PHASES, projection, "_id = ?", selectionArgs, null);

(assuming this refers to a context).

[also fetching an item using its ID is typically handled by a URI of the form "content://authority/items/#" that returns a single item, rather than specifying a selection on a URI that generally returns multiple items]

share|improve this answer

Your Answer


