This post introduces the
LoaderManager class. This is the second of a series of posts I will
be writing on Loaders and the LoaderManager:
Note: Understanding the
LoaderManager requires some general knowledge about how
Loaders work. Their implementation will be covered extensively in my
next post. For now, you should think
of Loaders as simple, self-contained objects that (1) load data on a separate thread, and (2) monitor the underlying data
source for updates, re-querying when changes are detected. This is more than enough to get you through the contents
of this post. All Loaders are assumed to be 100% correctly implemented in this post.
What is the
Simply stated, the
LoaderManager is responsible for managing one or more
associated with an Activity or Fragment. Each Activity and each Fragment has exactly one LoaderManager
instance that is in charge of starting, stopping, retaining, restarting, and destroying its Loaders.
These events are sometimes initiated directly by the client, by calling
destroyLoader(). Just as often, however, these events
are triggered by major Activity/Fragment lifecycle events. For example, when an Activity is destroyed,
the Activity instructs its LoaderManager to destroy and close its Loaders (as well as any resources
associated with them, such as a Cursor).