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 the List of Runs

The current implementation of RunListFragment asks the RunManager directly for the RunCursor representing the list of runs in onCreate(Bundle). In this section, you will introduce a loader to indirectly execute this query on another thread. The RunListFragment will tell the LoaderManager to start (and restart) the loader and implement the LoaderCallbacks to know when the data is ready.

To simplify the code within the RunListFragment (and elsewhere, later), first create an abstract AsyncTaskLoader subclass called SQLiteCursorLoader as in Listing 35.1. This class mimics most of the code in CursorLoader, without the requirement of using a ContentProvider.

Listing 35.1  A loader for SQLite cursors (SQLiteCursorLoader.java)

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