SUNSHINE APP : Cursor Loader

* 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: S0904-UsingCursorLoader

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s