CursorLoader


class CursorLoader : AsyncTaskLoader


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

Summary

Public constructors

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 functions

Unit

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

Unit

Sends the result of the load to the registered listener.

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

This function is deprecated.

Consider using enableDebugLogging to understand the series of operations performed by LoaderManager.

Array<String!>?
String?
Array<String!>?
String?
Uri
Cursor!

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

Unit

Called if the task was canceled before it was completed.

Unit
setProjection(projection: Array<String!>?)
Unit
setSelection(selection: String?)
Unit
setSelectionArgs(selectionArgs: Array<String!>?)
Unit
setSortOrder(sortOrder: String?)
Unit
setUri(uri: Uri)

Protected functions

Unit

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

Unit

Starts an asynchronous load of the contacts list data.

Unit

Must be called from the UI thread

Inherited functions

From androidx.loader.content.AsyncTaskLoader
Executor

Returns the Executor to use for this Loader's AsyncTasks.

Boolean

Returns true if the current invocation of loadInBackground is being canceled.

Boolean

Subclasses must implement this to take care of requests to cancelLoad.

Unit

Subclasses must implement this to take care of requests to forceLoad.

D?

Calls loadInBackground.

Unit

Set amount to throttle updates by.

From androidx.loader.content.Loader
Unit

This function will normally be called for you automatically by LoaderManager when restarting a Loader.

Boolean

Attempt to cancel the current load task.

Unit

Commit that you have actually fully processed a content change that was returned by takeContentChanged.

String
dataToString(data: D?)

For debugging, converts an instance of the Loader's data class to a string that can be printed.

Unit

Informs the registered OnLoadCanceledListener that the load has been canceled.

Unit

Force an asynchronous load.

Context
Int
Boolean

Return whether this loader has been abandoned.

Boolean

Return whether this load has been reset.

Boolean

Return whether this load has been started.

Unit

Subclasses implement this to take care of being abandoned.

Unit

Called when ForceLoadContentObserver detects a change.

Unit

Registers a class that will receive callbacks when a load is complete.

Unit

Registers a listener that will receive callbacks when a load is canceled.

Unit

This function will normally be called for you automatically by LoaderManager when destroying a Loader.

Unit

Report that you have abandoned the processing of a content change that was returned by takeContentChanged and would like to rollback to the state where there is again a pending content change.

Unit

This function will normally be called for you automatically by LoaderManager when the associated fragment/activity is being started.

Unit

This function will normally be called for you automatically by LoaderManager when the associated fragment/activity is being stopped.

Boolean

Take the current flag indicating whether the loader's content had changed while it was stopped.

String
Unit

Remove a listener that was previously added with registerListener.

Unit

Unregisters a listener that was previously added with registerOnLoadCanceledListener.

Public constructors

CursorLoader

Added in 1.0.0
CursorLoader(context: Context)

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

CursorLoader

Added in 1.0.0
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 functions

cancelLoadInBackground

fun cancelLoadInBackground(): Unit

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.

See also
loadInBackground

deliverResult

Added in 1.0.0
fun deliverResult(data: Cursor!): Unit

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: Cursor!

the result of the load

dump

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

getProjection

Added in 1.0.0
fun getProjection(): Array<String!>?

getSelection

Added in 1.0.0
fun getSelection(): String?

getSelectionArgs

Added in 1.0.0
fun getSelectionArgs(): Array<String!>?

getSortOrder

Added in 1.0.0
fun getSortOrder(): String?

getUri

Added in 1.0.0
fun getUri(): Uri

loadInBackground

Added in 1.2.0-alpha01
fun loadInBackground(): Cursor!

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.

Returns
Cursor!

The result of the load operation.

Throws
androidx.core.os.OperationCanceledException

if the load is canceled during execution.

onCanceled

Added in 1.0.0
fun onCanceled(data: Cursor!): Unit

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: Cursor!

The value that was returned by loadInBackground, or null if the task threw OperationCanceledException.

setProjection

Added in 1.0.0
fun setProjection(projection: Array<String!>?): Unit

setSelection

Added in 1.0.0
fun setSelection(selection: String?): Unit

setSelectionArgs

Added in 1.0.0
fun setSelectionArgs(selectionArgs: Array<String!>?): Unit

setSortOrder

Added in 1.0.0
fun setSortOrder(sortOrder: String?): Unit

setUri

Added in 1.0.0
fun setUri(uri: Uri): Unit

Protected functions

onReset

protected fun onReset(): Unit

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

protected fun onStartLoading(): Unit

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

protected fun onStopLoading(): Unit

Must be called from the UI thread