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. The Loaders framework was created to solve a couple of issues related to asynchronous loading in Activities and Fragments:
- Background processing: The heavy lifting is automatically performed on a background thread, and the results are safely introduced to the main thread on completion.
- Result caching: Loaded data can be cached and redelivered on repeat calls for speed and efficiency.
- Lifecycle awareness: The framework gives us control over when a Loader instance is destroyed, and allows Loaders to live outside the
Activity
lifecycle, making their data available across the application and acrossActivity
restarts. - Data change management: Loaders monitor their underlying data source, and reload their data in the background when necessary. The framework includes lifecycle callbacks that...