Added in API level 11
Deprecated in API level 28

LoaderManager


abstract class LoaderManager
kotlin.Any
   ↳ android.app.LoaderManager

Interface associated with an Activity or Fragment for managing one or more android.content.Loader instances associated with it. This helps an application manage longer-running operations in conjunction with the Activity or Fragment lifecycle; the most common use of this is with a android.content.CursorLoader, however applications are free to write their own loaders for loading other types of data. While the LoaderManager API was introduced in android.os.Build.VERSION_CODES#HONEYCOMB, a version of the API at is also available for use on older platforms through androidx.fragment.app.FragmentActivity. See the blog post Fragments For All for more details.

As an example, here is the full implementation of a Fragment that displays a android.widget.ListView containing the results of a query against the contacts content provider. It uses a android.content.CursorLoader to manage the query on the provider.

Summary

Nested classes
abstract

Callback interface for a client to interact with the manager.

Public constructors

Public methods
abstract Unit

Stops and removes the loader with the given ID.

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

Print the LoaderManager's state into the given stream.

open static Unit

Control whether the framework's internal loader manager debugging logs are turned on.

abstract Loader<D>!

Return the Loader with the given id or null if no matching Loader is found.

abstract Loader<D>!
initLoader(id: Int, args: Bundle!, callback: LoaderManager.LoaderCallbacks<D>!)

Ensures a loader is initialized and active.

abstract Loader<D>!
restartLoader(id: Int, args: Bundle!, callback: LoaderManager.LoaderCallbacks<D>!)

Starts a new or restarts an existing android.content.Loader in this manager, registers the callbacks to it, and (if the activity/fragment is currently started) starts loading it.

Public constructors

LoaderManager

LoaderManager()

Public methods

destroyLoader

Added in API level 11
abstract fun destroyLoader(id: Int): Unit

Deprecated: Deprecated in Java.

Stops and removes the loader with the given ID. If this loader had previously reported data to the client through LoaderCallbacks#onLoadFinished(Loader, Object), a call will be made to LoaderCallbacks#onLoaderReset(Loader).

dump

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

Deprecated: Deprecated in Java.

Print the LoaderManager'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.

enableDebugLogging

Added in API level 11
open static fun enableDebugLogging(enabled: Boolean): Unit

Deprecated: Deprecated in Java.

Control whether the framework's internal loader manager debugging logs are turned on. If enabled, you will see output in logcat as the framework performs loader operations.

getLoader

Added in API level 11
abstract fun <D : Any!> getLoader(id: Int): Loader<D>!

Deprecated: Deprecated in Java.

Return the Loader with the given id or null if no matching Loader is found.

initLoader

Added in API level 11
abstract fun <D : Any!> initLoader(
    id: Int,
    args: Bundle!,
    callback: LoaderManager.LoaderCallbacks<D>!
): Loader<D>!

Deprecated: Deprecated in Java.

Ensures a loader is initialized and active. If the loader doesn't already exist, one is created and (if the activity/fragment is currently started) starts the loader. Otherwise the last created loader is re-used.

In either case, the given callback is associated with the loader, and will be called as the loader state changes. If at the point of call the caller is in its started state, and the requested loader already exists and has generated its data, then callback LoaderCallbacks#onLoadFinished will be called immediately (inside of this function), so you must be prepared for this to happen.

Parameters
id Int: A unique identifier for this loader. Can be whatever you want. Identifiers are scoped to a particular LoaderManager instance.
args Bundle!: Optional arguments to supply to the loader at construction. If a loader already exists (a new one does not need to be created), this parameter will be ignored and the last arguments continue to be used.
callback LoaderManager.LoaderCallbacks<D>!: Interface the LoaderManager will call to report about changes in the state of the loader. Required.

restartLoader

Added in API level 11
abstract fun <D : Any!> restartLoader(
    id: Int,
    args: Bundle!,
    callback: LoaderManager.LoaderCallbacks<D>!
): Loader<D>!

Deprecated: Deprecated in Java.

Starts a new or restarts an existing android.content.Loader in this manager, registers the callbacks to it, and (if the activity/fragment is currently started) starts loading it. If a loader with the same id has previously been started it will automatically be destroyed when the new loader completes its work. The callback will be delivered before the old loader is destroyed.

Parameters
id Int: A unique identifier for this loader. Can be whatever you want. Identifiers are scoped to a particular LoaderManager instance.
args Bundle!: Optional arguments to supply to the loader at construction.
callback LoaderManager.LoaderCallbacks<D>!: Interface the LoaderManager will call to report about changes in the state of the loader. Required.