The obvious applications include reading any kind of data from files or databases local to the device, or Android content providers, as we've done in the examples in this chapter.
One strong advantage of Loaders
over direct use of AsyncTask
is that their lifecycle is very flexible with respect to the Activity
and Fragment
lifecycles. Without any extra effort we can handle configuration changes such as an orientation change.
We can even start loading in one Activity
, navigate through the app, and collect the result in a completely separate Activity
, if that makes sense for our app.
In some ways, this decoupling from the Activity lifecycle makes Loader
a better candidate than AsyncTask
to perform network transfers such as HTTP downloads; however, they require more code and still aren't a perfect fit.
The framework is very powerful for managing asynchronous data loading; however, it does not provide a mechanism to show the loading progress, as we have on the AsyncTask
framework...