AsyncTaskLoader


abstract class AsyncTaskLoader<D> : Loader

Known direct subclasses
CursorLoader

Static library support version of the framework's android.content.CursorLoader.


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

Public functions

Unit

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

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.

Boolean

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

abstract D?

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

Unit
onCanceled(data: D?)

Called if the task was canceled before it was completed.

Unit

Set amount to throttle updates by.

Protected functions

Executor

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

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.

Inherited functions

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

Sends the result of the load to the registered listener.

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

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

Unit

Subclasses must implement this to take care of loading their data, as per startLoading.

Unit

Subclasses must implement this to take care of stopping their loader, as per stopLoading.

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

AsyncTaskLoader

Added in 1.0.0
AsyncTaskLoader(context: Context)

Public functions

cancelLoadInBackground

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

dump

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

isLoadInBackgroundCanceled

Added in 1.0.0
fun isLoadInBackgroundCanceled(): Boolean

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

Returns
Boolean

True if the current invocation of loadInBackground is being canceled.

See also
loadInBackground

loadInBackground

Added in 1.0.0
abstract fun loadInBackground(): D?

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
D?

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: D?): 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: D?

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

setUpdateThrottle

Added in 1.0.0
fun setUpdateThrottle(delayMS: Long): Unit

Set amount to throttle updates by. This is the minimum time from when the last loadInBackground call has completed until a new load is scheduled.

Parameters
delayMS: Long

Amount of delay, in milliseconds.

Protected functions

getExecutor

Added in 1.1.0
protected fun getExecutor(): Executor

Returns the Executor to use for this Loader's AsyncTasks. By default THREAD_POOL_EXECUTOR will be used. Override this method to return a custom executor. Note that this method will only be called once before this Loader's first AsyncTask is run. It is up to the Loader to shut down the Executor at the appropriate place (e.g. in onAbandon) if necessary.

Returns
Executor

the Executor to use for this Loader's AsyncTasks.

onCancelLoad

protected fun onCancelLoad(): Boolean

Subclasses must implement this to take care of requests to cancelLoad. This will always be called from the process's main thread.

Returns
Boolean

Returns false if the task could not be canceled, typically because it has already completed normally, or because startLoading hasn't been called; returns true otherwise. When true is returned, the task is still running and the OnLoadCanceledListener will be called when the task completes.

onForceLoad

protected fun onForceLoad(): Unit

Subclasses must implement this to take care of requests to forceLoad. This will always be called from the process's main thread.

onLoadInBackground

Added in 1.0.0
protected fun onLoadInBackground(): D?

Calls loadInBackground. This method is reserved for use by the loader framework. Subclasses should override loadInBackground instead of this method.

Returns
D?

The result of the load operation.

Throws
androidx.core.os.OperationCanceledException

if the load is canceled during execution.

See also
loadInBackground