added in version 22.1.0
belongs to Maven artifact com.android.support:loader:28.0.0-alpha1

CursorLoader

public class CursorLoader
extends AsyncTaskLoader<Cursor>

java.lang.Object
   ↳ android.support.v4.content.Loader<android.database.Cursor>
     ↳ android.support.v4.content.AsyncTaskLoader<android.database.Cursor>
       ↳ android.support.v4.content.CursorLoader


Static library support version of the framework's 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.

Summary

Public constructors

CursorLoader(Context context)

Creates an empty unspecified CursorLoader.

CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

Creates a fully-specified CursorLoader.

Public methods

void cancelLoadInBackground()

Called on the main thread to abort a load in progress.

void deliverResult(Cursor cursor)

Sends the result of the load to the registered listener.

void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

Print the Loader's state into the given stream.

String[] getProjection()
String getSelection()
String[] getSelectionArgs()
String getSortOrder()
Uri getUri()
Cursor loadInBackground()

Called on a worker thread to perform the actual load and to return the result of the load operation.

void onCanceled(Cursor cursor)

Called if the task was canceled before it was completed.

void setProjection(String[] projection)
void setSelection(String selection)
void setSelectionArgs(String[] selectionArgs)
void setSortOrder(String sortOrder)
void setUri(Uri uri)

Protected methods

void onReset()

Subclasses must implement this to take care of resetting their loader, as per reset().

void onStartLoading()

Starts an asynchronous load of the contacts list data.

void onStopLoading()

Must be called from the UI thread

Inherited methods

From class android.support.v4.content.AsyncTaskLoader
From class android.support.v4.content.Loader
From class java.lang.Object

Public constructors

CursorLoader

added in version 22.1.0
CursorLoader (Context context)

Creates an empty unspecified CursorLoader. You must follow this with calls to setUri(Uri), setSelection(String), etc to specify the query to perform.

Parameters
context Context

CursorLoader

added in version 22.1.0
CursorLoader (Context context, 
                Uri uri, 
                String[] projection, 
                String selection, 
                String[] selectionArgs, 
                String sortOrder)

Creates a fully-specified CursorLoader. See ContentResolver.query() for documentation on the meaning of the parameters. These will be passed as-is to that call.

Parameters
context Context

uri Uri

projection String

selection String

selectionArgs String

sortOrder String

Public methods

cancelLoadInBackground

added in version 24.1.0
void cancelLoadInBackground ()

Called on the main thread to abort a load in progress. Override this method to abort the current invocation of loadInBackground() that is running in the background on a worker thread. This method should do nothing if loadInBackground() has not started running or if it has already finished.

deliverResult

added in version 22.1.0
void deliverResult (Cursor cursor)

Sends the result of the load to the registered listener. Should only be called by subclasses. Must be called from the process's main thread.

Parameters
cursor Cursor: the result of the load

dump

added in version 22.1.0
void dump (String prefix, 
                FileDescriptor fd, 
                PrintWriter writer, 
                String[] args)

Print the Loader's state into the given stream.

Parameters
prefix String: Text to print at the front of each line.

fd FileDescriptor: The raw file descriptor that the dump is being sent to.

writer PrintWriter: A PrintWriter to which the dump is to be set.

args String: Additional arguments to the dump request.

getProjection

added in version 22.1.0
String[] getProjection ()

Returns
String[]

getSelection

added in version 22.1.0
String getSelection ()

Returns
String

getSelectionArgs

added in version 22.1.0
String[] getSelectionArgs ()

Returns
String[]

getSortOrder

added in version 22.1.0
String getSortOrder ()

Returns
String

getUri

added in version 22.1.0
Uri getUri ()

Returns
Uri

loadInBackground

added in version 22.1.0
Cursor loadInBackground ()

Called on a worker thread to perform the actual load and to return the result of the load operation. Implementations should not deliver the result directly, but should return them from this method, which will eventually end up calling deliverResult(D) on the UI thread. If implementations need to process the results on the UI thread they may override deliverResult(D) and do so there. To support cancellation, this method should periodically check the value of isLoadInBackgroundCanceled() and terminate when it returns true. Subclasses may also override cancelLoadInBackground() to interrupt the load directly instead of polling isLoadInBackgroundCanceled(). When the load is canceled, this method may either return normally or throw OperationCanceledException. In either case, the Loader will call onCanceled(D) to perform post-cancellation cleanup and to dispose of the result object, if any.

Returns
Cursor The result of the load operation.

onCanceled

added in version 22.1.0
void onCanceled (Cursor cursor)

Called if the task was canceled before it was completed. Gives the class a chance to clean up post-cancellation and to properly dispose of the result.

Parameters
cursor Cursor: The value that was returned by loadInBackground(), or null if the task threw OperationCanceledException.

setProjection

added in version 22.1.0
void setProjection (String[] projection)

Parameters
projection String

setSelection

added in version 22.1.0
void setSelection (String selection)

Parameters
selection String

setSelectionArgs

added in version 22.1.0
void setSelectionArgs (String[] selectionArgs)

Parameters
selectionArgs String

setSortOrder

added in version 22.1.0
void setSortOrder (String sortOrder)

Parameters
sortOrder String

setUri

added in version 22.1.0
void setUri (Uri uri)

Parameters
uri Uri

Protected methods

onReset

added in version 22.1.0
void onReset ()

Subclasses must implement this to take care of resetting their loader, as per reset(). This is not called by clients directly, but as a result of a call to reset(). This will always be called from the process's main thread.

onStartLoading

added in version 22.1.0
void onStartLoading ()

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

onStopLoading

added in version 22.1.0
void onStopLoading ()

Must be called from the UI thread