Google is committed to advancing racial equity for Black communities. See how.

Loader

open class Loader<D : Any!>
kotlin.Any
   ↳ androidx.loader.content.Loader

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

Nested classes

An implementation of a ContentObserver that takes care of connecting it to the Loader to have the loader re-load its data when the observer is told it has changed.

abstract

Interface that is implemented to discover when a Loader has been canceled before it finished loading its data.

abstract

Interface that is implemented to discover when a Loader has finished loading its data.

Public constructors
<init>(@NonNull context: Context)

Stores away the application context associated with context.

Public methods
open Unit

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

open Boolean

Attempt to cancel the current load task.

open Unit

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

open String
dataToString(@Nullable data: D?)

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

open Unit

Informs the registered OnLoadCanceledListener that the load has been canceled.

open Unit
deliverResult(@Nullable data: D?)

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 Unit

Force an asynchronous load.

open Context

open Int

open Boolean

Return whether this loader has been abandoned.

open Boolean

Return whether this load has been reset.

open Boolean

Return whether this load has been started.

open Unit

Called when ForceLoadContentObserver detects a change.

open Unit
registerListener(id: Int, @NonNull listener: Loader.OnLoadCompleteListener<D>)

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

open Unit

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

open Unit

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

open 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.

open Unit

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

open Boolean

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

open String

open Unit

Remove a listener that was previously added with registerListener.

open Unit

Unregisters a listener that was previously added with registerOnLoadCanceledListener.

Protected methods
open Unit

Subclasses implement this to take care of being abandoned.

open Boolean

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

open Unit

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

open Unit

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

open Unit

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

open Unit

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

Public constructors

<init>

Loader(@NonNull context: Context)

Stores away the application context associated with context. Since Loaders can be used across multiple activities it's dangerous to store the context directly; always use getContext() to retrieve the Loader's Context, don't use the constructor argument directly. The Context returned by getContext is safe to use across Activity instances.

Parameters
context Context: used to retrieve the application context.

Public methods

abandon

@MainThread open fun abandon(): Unit

This function will normally be called for you automatically by LoaderManager when restarting a Loader. When using a Loader with LoaderManager, you must not call this method yourself, or you will conflict with its management of the Loader. Tell the Loader that it is being abandoned. This is called prior to reset to have it retain its current data but not report any new data.

Must be called from the process's main thread.

cancelLoad

@MainThread open fun cancelLoad(): Boolean

Attempt to cancel the current load task. Must be called on the main thread of the process.

Cancellation is not an immediate operation, since the load is performed in a background thread. If there is currently a load in progress, this method requests that the load be canceled, and notes this is the case; once the background thread has completed its work its remaining state will be cleared. If another load request comes in during this time, it will be held until the canceled load is complete.

Return
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.

commitContentChanged

open fun commitContentChanged(): Unit

Commit that you have actually fully processed a content change that was returned by takeContentChanged. This is for use with rollbackContentChanged() to handle situations where a load is cancelled. Call this when you have completely processed a load without it being cancelled.

dataToString

@NonNull open fun dataToString(@Nullable data: D?): String

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

deliverCancellation

@MainThread open fun deliverCancellation(): Unit

Informs the registered OnLoadCanceledListener that the load has been canceled. Should only be called by subclasses. Must be called from the process's main thread.

deliverResult

@MainThread open fun deliverResult(@Nullable data: D?): 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 D?: the result of the load

dump

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

Deprecated: Consider using LoaderManager#enableDebugLogging(boolean) to understand the series of operations performed by LoaderManager.

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.

forceLoad

@MainThread open fun forceLoad(): Unit

Force an asynchronous load. Unlike startLoading() this will ignore a previously loaded data set and load a new one. This simply calls through to the implementation's onForceLoad(). You generally should only call this when the loader is started -- that is, isStarted() returns true.

Must be called from the process's main thread.

getContext

@NonNull open fun getContext(): Context
Return
Context an application context retrieved from the Context passed to the constructor.

getId

open fun getId():