35Loading Asynchronous Data With Loaders

In Chapter 34 you implemented data storage in RunTracker using SQLite and used Cursors on the main thread of the application. This was a cop-out, however: it’s a best practice to keep database work off of the main thread as much as possible.

In this chapter, you will use Loaders to pull data for runs and locations from the database on a background thread. The loader API was introduced in Android 3.0 (Honeycomb) and is also available in the support library, so there is no reason not to use them in a modern application.

Loaders and the LoaderManager

A loader is designed to load some kind of data (an object) from some source. The source could be disk, a database, a ContentProvider, the network, or another process. ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.