Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the scope of LoaderManager?

When creating an Android application using Loaders, should every activity and fragment have its own LoaderManager? Or should there only be one LoaderManager that the application owns? And lastly, are the "unique IDs" that are used to identify specific LoaderManagers visible outside of the class?

Specifically, I'm having trouble deciding which classes in my application should implement the LoaderCallback<Cursor> methods (i.e. should each fragment implement these callbacks, or should I have one fragment implement the callbacks and query the results, sending them to other fragments/activities as necessary)?

Thanks in advance to anyone who can help me out! I couldn't find too much information about this online.

like image 953
Alex Lockwood Avatar asked Dec 25 '11 17:12

Alex Lockwood


People also ask

What is LoaderManager?

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.

What are loaders 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.


1 Answers

LoaderManger's are managed and owned by the activity. You can create the actual loaders in your fragments or the activity, they will be manged by the same LoaderManager. Unique ID's are to identify different loaders you might have in the same activitiy. For example ID=0 -> FooLoader, ID=1 -> BarLoader, etc.

like image 119
Nikolay Elenkov Avatar answered Sep 28 '22 07:09

Nikolay Elenkov