Loading a Single Run

The new SQLiteCursorLoader class is fine for loading data that you want to remain in a cursor (such as a list of things), but in the RunFragment, you are loading two individual objects and the cursor is hidden by the RunManager. To best handle loading arbitrary data, you need a more generic loader.

In this section, you will create a new DataLoader class that is a subclass of AsyncTaskLoader. DataLoader will take care of some simple tasks that any subclass of AsyncTaskLoader should, leaving only the implementation of loadInBackground() to its own subclasses.

Create DataLoader using the code in Listing 35.5.

Listing 35.5  A simple loader for data (DataLoader.java)

p​u​b​l​i​c​ ​a​b​s​t​r​a​c​t​ ​c​l​a​s​s​ ​D​a​t​a​L​o​a​d​e​r​<​D​>​ ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.