* Reference: Udacity Nanodegree Program- Become an Android Developer *
A CursorLoader is a subclass of AsyncTaskLoader that queries a ContentProvider, via a ContentResolver and specific URI, and returns a Cursor of desired data. This loader runs its query on a background thread so that it doesn’t block the UI.
When a CursorLoader is active, it is tied to a URI, and you can choose to have it monitor this URI for any changes in data; this means that the CursorLoader can deliver new results whenever the contents of our weather database change, and we can automatically update the UI to reflect any weather change!
github:
Notes on Solution Code
One of the biggest changes to the Sunshine code was to update the ForecastAdapter and change its onBindViewHolder method so that it takes all of the data from a cursor and uses that to populate the views.
- Modify the ForecastAdapter
- Our first step will be to modify the ForecastAdapter so that it creates views based on the data in a Cursor (and not an array of Strings).
- Create a CursorLoader in MainActivity
- The next step will be to update the code in the MainActivity and replace the AsyncTaskLoader with a CursorLoader.