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