FileDocCategorySizeDatePackage
LoaderManager.javaAPI DocAndroid 5.1 API37420Thu Mar 12 22:22:10 GMT 2015android.app

LoaderManager

public abstract class LoaderManager extends Object
Interface associated with an {@link Activity} or {@link Fragment} for managing one or more {@link 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 {@link 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 {@link android.os.Build.VERSION_CODES#HONEYCOMB}, a version of the API at is also available for use on older platforms through {@link android.support.v4.app.FragmentActivity}. See the blog post Fragments For All for more details.

As an example, here is the full implementation of a {@link Fragment} that displays a {@link android.widget.ListView} containing the results of a query against the contacts content provider. It uses a {@link android.content.CursorLoader} to manage the query on the provider. {@sample development/samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java fragment_cursor}

Developer Guides

For more information about using loaders, read the Loaders developer guide.

Fields Summary
Constructors Summary
Methods Summary
public abstract voiddestroyLoader(int id)
Stops and removes the loader with the given ID. If this loader had previously reported data to the client through {@link LoaderCallbacks#onLoadFinished(Loader, Object)}, a call will be made to {@link LoaderCallbacks#onLoaderReset(Loader)}.

public abstract voiddump(java.lang.String prefix, java.io.FileDescriptor fd, java.io.PrintWriter writer, java.lang.String[] args)
Print the LoaderManager's state into the given stream.

param
prefix Text to print at the front of each line.
param
fd The raw file descriptor that the dump is being sent to.
param
writer A PrintWriter to which the dump is to be set.
param
args Additional arguments to the dump request.

public static voidenableDebugLogging(boolean enabled)
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.

        LoaderManagerImpl.DEBUG = enabled;
    
public abstract android.content.LoadergetLoader(int id)
Return the Loader with the given id or null if no matching Loader is found.

public abstract android.content.LoaderinitLoader(int id, android.os.Bundle args, android.app.LoaderManager$LoaderCallbacks callback)
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 {@link LoaderCallbacks#onLoadFinished} will be called immediately (inside of this function), so you must be prepared for this to happen.

param
id A unique identifier for this loader. Can be whatever you want. Identifiers are scoped to a particular LoaderManager instance.
param
args 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.
param
callback Interface the LoaderManager will call to report about changes in the state of the loader. Required.

public abstract android.content.LoaderrestartLoader(int id, android.os.Bundle args, android.app.LoaderManager$LoaderCallbacks callback)
Starts a new or restarts an existing {@link 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.

param
id A unique identifier for this loader. Can be whatever you want. Identifiers are scoped to a particular LoaderManager instance.
param
args Optional arguments to supply to the loader at construction.
param
callback Interface the LoaderManager will call to report about changes in the state of the loader. Required.