O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​>​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required