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)

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.