Added in API level 11
Deprecated in API level 28

CursorLoader


open class CursorLoader : AsyncTaskLoader<Cursor!>
kotlin.Any
   ↳ android.content.Loader<D>
   ↳ android.content.AsyncTaskLoader<android.database.Cursor>
   ↳ android.content.CursorLoader

A loader that queries the ContentResolver and returns a Cursor. This class implements the Loader protocol in a standard way for querying cursors, building on AsyncTaskLoader to perform the cursor query on a background thread so that it does not block the application's UI.

A CursorLoader must be built with the full information for the query to perform, either through the CursorLoader(android.content.Context,android.net.Uri,java.lang.String[],java.lang.String,java.lang.String[],java.lang.String) or creating an empty instance with CursorLoader(android.content.Context) and filling in the desired parameters with setUri(android.net.Uri), setSelection(java.lang.String), setSelectionArgs(java.lang.String[]), setSortOrder(java.lang.String), and setProjection(java.lang.String[]).

Summary

Public constructors
CursorLoader(context: Context!)

Creates an empty unspecified CursorLoader.

CursorLoader(context: Context!, uri: Uri!, projection: Array<String!>!, selection: String!, selectionArgs: Array<String!>!, sortOrder: String!)

Creates a fully-specified CursorLoader.

Public methods
open Unit

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

open Unit

Sends the result of the load to the registered listener.

open Unit
dump(prefix: String!, fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!)

Print the Loader's state into the given stream.

open Array<String!>!

open String!

open Array<String!>!

open String!

open Uri!

open Cursor!

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

open Unit
onCanceled(cursor: Cursor!)

Called if the task was canceled before it was completed.

open Unit
setProjection(projection: Array<String!>!)

open Unit
setSelection(selection: String!)

open Unit
setSelectionArgs(selectionArgs: Array<String!>!)

open Unit
setSortOrder(sortOrder: String!)

open Unit
setUri(uri: Uri!)

Protected methods
open Unit

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

open Unit

Starts an asynchronous load of the data.

open Unit

Must be called from the UI thread

Inherited functions

Public constructors

CursorLoader

Added in API level 11
CursorLoader(context: Context!)

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

CursorLoader

Added in API level 11
CursorLoader(
    context: Context!,
    uri: Uri!,
    projection: Array<String!>!,
    selection: String!,
    selectionArgs: Array<String!>!,
    sortOrder: String!)

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.

Public methods

cancelLoadInBackground

Added in API level 16
Deprecated in API level 28
open fun cancelLoadInBackground(): Unit

Deprecated: Deprecated in Java.

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 API level 11
open fun deliverResult(cursor: Cursor!): Unit

Deprecated: Deprecated in Java.

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
data the result of the load

dump

Added in API level 11
open fun dump(
    prefix: String!,
    fd: FileDescriptor!,
    writer: PrintWriter!,
    args: Array<String!>!
): Unit

Deprecated: Deprecated in Java.

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 Array<String!>!: Additional arguments to the dump request.

getProjection

Added in API level 11
open fun getProjection(): Array<String!>!

Deprecated: Deprecated in Java.

getSelection

Added in API level 11
open fun getSelection(): String!

Deprecated: Deprecated in Java.

getSelectionArgs

Added in API level 11
open fun getSelectionArgs(): Array<String!>!

Deprecated: Deprecated in Java.

getSortOrder

Added in API level 11
open fun getSortOrder(): String!

Deprecated: Deprecated in Java.

getUri

Added in API level 11
open fun getUri(): Uri!

Deprecated: Deprecated in Java.

loadInBackground

Added in API level 11
open fun loadInBackground(): Cursor!

Deprecated: Deprecated in Java.

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 on the UI thread. If implementations need to process the results on the UI thread they may override deliverResult 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 to perform post-cancellation cleanup and to dispose of the result object, if any.

Return
Cursor! The result of the load operation.
Exceptions
android.os.OperationCanceledException if the load is canceled during execution.

onCanceled

Added in API level 11
open fun onCanceled(cursor: Cursor!): Unit

Deprecated: Deprecated in Java.

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
data The value that was returned by loadInBackground, or null if the task threw OperationCanceledException.

setProjection

Added in API level 11
open fun setProjection(projection: Array<String!>!): Unit

Deprecated: Deprecated in Java.

setSelection

Added in API level 11
open fun setSelection(selection: String!): Unit

Deprecated: Deprecated in Java.

setSelectionArgs

Added in API level 11
open fun setSelectionArgs(selectionArgs: Array<String!>!): Unit

Deprecated: Deprecated in Java.

setSortOrder

Added in API level 11
open fun setSortOrder(sortOrder: String!): Unit

Deprecated: Deprecated in Java.

setUri

Added in API level 11
open fun setUri(uri: Uri!): Unit

Deprecated: Deprecated in Java.

Protected methods

onReset

Added in API level 11
protected open fun onReset(): Unit

Deprecated: Deprecated in Java.

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 API level 11
protected open fun onStartLoading(): Unit

Deprecated: Deprecated in Java.

Starts an asynchronous load of the 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 API level 11
protected open fun onStopLoading(): Unit

Deprecated: Deprecated in Java.

Must be called from the UI thread