Introducing Loaders
As the name suggests, the job of Loader
is to load data on behalf of other parts of the application, and to make that data available across activities and fragments within the same process.
Loaders were introduced to the Android platform at API level 11, but are available for backwards compatibility through the support libraries. The examples in this chapter use the support library to target API levels 7 through 19.
Provided we implement our Loaders correctly, we get a number of benefits:
The heavy lifting is automatically performed on a background thread, and the results are safely introduced to the main thread on completion.
Loaded data can be cached and redelivered on repeat calls for speed and efficiency.
The framework gives us control over when a
Loader
instance is destroyed, and allows Loaders to live outside theActivity
lifecycle, making their data available across the application and acrossActivity
restarts.Loaders monitor their underlying datasource, and reload...