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 LoaderManager
s 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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With