Loader (Associate Android Developer Certification)

LoaderManager controls all loaders. LoaderCallbacks interface has 3 methods.

1. OnCreateLoader – here loader is created
2. OnLoadFinished – loader loaded data
3. OnLoaderReset – loader relodes data

Following is order of method calls when Activity created:

Application.onCreate()
Activity.onCreate()
LoaderManager.LoaderCallbacks.onCreateLoader()
Activity.onStart()
Activity.onResume()
LoaderManager.LoaderCallbacks.onLoadFinished()

Following is order of method calls when configuration change happens:

Application:config changed
Activity.onCreate
Activity.onStart
[No call to the onCreateLoader]
LoaderManager.LoaderCallbacks.onLoadFinished
[optionally if searchview has text in it]
SearchView.onQueryChangeText()
RestartLoader
LoaderManager.LoaderCallbacks.onCreateLoader
LoaderManager.LoaderCallbacks.onLoadFinished

Following is order of method calls when activity destroys:

Activity.onStop()
Activity.onDestroy()
LoaderManager.LoaderCallbacks.onLoaderReset()

Loader is dedicated to load data from disk, database, content provider, network or other process asyncroniously.
There are 3 types of Loader: Loader, AsyncTaskLoader and CursorLoader.Base Loader class is not much useful.