FileDocCategorySizeDatePackage
CursorLoader.javaAPI DocAndroid 5.1 API6288Thu Mar 12 22:22:56 GMT 2015android.support.v4.content

CursorLoader

public class CursorLoader extends AsyncTaskLoader
Static library support version of the framework's {@link android.content.CursorLoader}. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Fields Summary
final ForceLoadContentObserver
mObserver
android.net.Uri
mUri
String[]
mProjection
String
mSelection
String[]
mSelectionArgs
String
mSortOrder
android.database.Cursor
mCursor
Constructors Summary
public CursorLoader(android.content.Context context)
Creates an empty unspecified CursorLoader. You must follow this with calls to {@link #setUri(Uri)}, {@link #setSelection(String)}, etc to specify the query to perform.

        super(context);
        mObserver = new ForceLoadContentObserver();
    
public CursorLoader(android.content.Context context, android.net.Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Creates a fully-specified CursorLoader. See {@link android.content.ContentResolver#query(Uri, String[], String, String[], String) ContentResolver.query()} for documentation on the meaning of the parameters. These will be passed as-is to that call.

        super(context);
        mObserver = new ForceLoadContentObserver();
        mUri = uri;
        mProjection = projection;
        mSelection = selection;
        mSelectionArgs = selectionArgs;
        mSortOrder = sortOrder;
    
Methods Summary
public voiddeliverResult(android.database.Cursor cursor)

        if (isReset()) {
            // An async query came in while the loader is stopped
            if (cursor != null) {
                cursor.close();
            }
            return;
        }
        Cursor oldCursor = mCursor;
        mCursor = cursor;

        if (isStarted()) {
            super.deliverResult(cursor);
        }

        if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
            oldCursor.close();
        }
    
public voiddump(java.lang.String prefix, java.io.FileDescriptor fd, java.io.PrintWriter writer, java.lang.String[] args)

        super.dump(prefix, fd, writer, args);
        writer.print(prefix); writer.print("mUri="); writer.println(mUri);
        writer.print(prefix); writer.print("mProjection=");
                writer.println(Arrays.toString(mProjection));
        writer.print(prefix); writer.print("mSelection="); writer.println(mSelection);
        writer.print(prefix); writer.print("mSelectionArgs=");
                writer.println(Arrays.toString(mSelectionArgs));
        writer.print(prefix); writer.print("mSortOrder="); writer.println(mSortOrder);
        writer.print(prefix); writer.print("mCursor="); writer.println(mCursor);
        writer.print(prefix); writer.print("mContentChanged="); writer.println(mContentChanged);
    
public java.lang.String[]getProjection()

        return mProjection;
    
public java.lang.StringgetSelection()

        return mSelection;
    
public java.lang.String[]getSelectionArgs()

        return mSelectionArgs;
    
public java.lang.StringgetSortOrder()

        return mSortOrder;
    
public android.net.UrigetUri()

        return mUri;
    
public android.database.CursorloadInBackground()

        Cursor cursor = getContext().getContentResolver().query(mUri, mProjection, mSelection,
                mSelectionArgs, mSortOrder);
        if (cursor != null) {
            // Ensure the cursor window is filled
            cursor.getCount();
            cursor.registerContentObserver(mObserver);
        }
        return cursor;
    
public voidonCanceled(android.database.Cursor cursor)

        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    
protected voidonReset()

        super.onReset();
        
        // Ensure the loader is stopped
        onStopLoading();

        if (mCursor != null && !mCursor.isClosed()) {
            mCursor.close();
        }
        mCursor = null;
    
protected voidonStartLoading()
Starts an asynchronous load of the contacts list data. When the result is ready the callbacks will be called on the UI thread. If a previous load has been completed and is still valid the result may be passed to the callbacks immediately. Must be called from the UI thread

        if (mCursor != null) {
            deliverResult(mCursor);
        }
        if (takeContentChanged() || mCursor == null) {
            forceLoad();
        }
    
protected voidonStopLoading()
Must be called from the UI thread

        // Attempt to cancel the current load task if possible.
        cancelLoad();
    
public voidsetProjection(java.lang.String[] projection)

        mProjection = projection;
    
public voidsetSelection(java.lang.String selection)

        mSelection = selection;
    
public voidsetSelectionArgs(java.lang.String[] selectionArgs)

        mSelectionArgs = selectionArgs;
    
public voidsetSortOrder(java.lang.String sortOrder)

        mSortOrder = sortOrder;
    
public voidsetUri(android.net.Uri uri)

        mUri = uri;