public abstract class LoaderManager extends Object
Activity
or Fragment
for managing
one or more 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
CursorLoader
, however applications are free to write
their own loaders for loading other types of data.
While the LoaderManager API was introduced in
Build.VERSION_CODES.HONEYCOMB
, a version of the API
at is also available for use on older platforms through
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 ListView
containing the results of
a query against the contacts content provider. It uses a
CursorLoader
to manage the query on the provider.
For more information about using loaders, read the Loaders developer guide.
Modifier and Type | Class and Description |
---|---|
static interface |
LoaderManager.LoaderCallbacks<D>
Callback interface for a client to interact with the manager.
|
Constructor and Description |
---|
LoaderManager() |
Modifier and Type | Method and Description |
---|---|
abstract void |
destroyLoader(int id)
Stops and removes the loader with the given ID.
|
abstract void |
dump(String prefix,
FileDescriptor fd,
PrintWriter writer,
String[] args)
Print the LoaderManager's state into the given stream.
|
static void |
enableDebugLogging(boolean enabled)
Control whether the framework's internal loader manager debugging
logs are turned on.
|
abstract <D> Loader<D> |
getLoader(int id)
Return the Loader with the given id or null if no matching Loader
is found.
|
abstract <D> Loader<D> |
initLoader(int id,
Bundle args,
LoaderManager.LoaderCallbacks<D> callback)
Ensures a loader is initialized and active.
|
abstract <D> Loader<D> |
restartLoader(int id,
Bundle args,
LoaderManager.LoaderCallbacks<D> callback)
Starts a new or restarts an existing
Loader in
this manager, registers the callbacks to it,
and (if the activity/fragment is currently started) starts loading it. |
public abstract <D> Loader<D> initLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback)
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 LoaderManager.LoaderCallbacks.onLoadFinished(android.content.Loader<D>, D)
will
be called immediately (inside of this function), so you must be prepared
for this to happen.
id
- A unique identifier for this loader. Can be whatever you want.
Identifiers are scoped to a particular LoaderManager instance.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.callback
- Interface the LoaderManager will call to report about
changes in the state of the loader. Required.public abstract <D> Loader<D> restartLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback)
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.id
- A unique identifier for this loader. Can be whatever you want.
Identifiers are scoped to a particular LoaderManager instance.args
- Optional arguments to supply to the loader at construction.callback
- Interface the LoaderManager will call to report about
changes in the state of the loader. Required.public abstract void destroyLoader(int id)
LoaderManager.LoaderCallbacks.onLoadFinished(Loader, Object)
, a call
will be made to LoaderManager.LoaderCallbacks.onLoaderReset(Loader)
.public abstract <D> Loader<D> getLoader(int id)
public abstract void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
prefix
- Text to print at the front of each line.fd
- The raw file descriptor that the dump is being sent to.writer
- A PrintWriter to which the dump is to be set.args
- Additional arguments to the dump request.public static void enableDebugLogging(boolean enabled)