Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does LoaderManager do?

I am trying to understand what does LoaderManager do. Can anyone share an example with it? Must I use them when I create a cursor? If not how should I use? A simple example is very appreciated.

like image 968
Mustafa Güven Avatar asked Aug 23 '11 07:08

Mustafa Güven


People also ask

What is LoaderManager?

Simply stated, the LoaderManager is responsible for managing one or more Loader s 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 Loader s.

What is loader manager in android?

Loaders in Android is an abstract class implementation of Loader and two default classes, which are provided by Android, I.E. AsyncTaskLoader , and cursor loaders. There is only one Loader instance per activity/fragment and is created by Loader managers. LoaderManager can manage multiple instances of Loaders.

What does the startManagingCursor () function do?

startManagingCursor manages Cursors, whereas the LoaderManager manages Loader<D> objects. The advantage here is that Loader<D> is generic, where D is the container object that holds the loaded data. In other words, the data source doesn't have to be a Cursor; it could be a List , a JSONArray … anything.

What is the importance of loader in Android programming?

Loaders persist and cache results across configuration changes to prevent duplicate queries. Loaders can implement an observer to monitor for changes in the underlying data source. For example, CursorLoader automatically registers a ContentObserver to trigger a reload when data changes.


1 Answers

Simply stated, the LoaderManager is responsible for managing one or more Loaders 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.

There is a pretty extensive and in-depth blog post on the LoaderManager... check it out here:

Understanding the LoaderManager (part 2)

like image 198
Adrian Monk Avatar answered Sep 21 '22 21:09

Adrian Monk