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
)
public abstract class DataLoader<D> extends AsyncTaskLoader<D> { ...
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.