Building responsive apps with CursorLoader
CursorLoader
is a specialized subclass of AsyncTaskLoader
that uses its lifecycle methods to correctly manage the resources associated with a database Cursor
.
A database Cursor
is a little like an Iterator, in that it allows you to scroll through a dataset without having to worry where exactly the dataset is coming from or what data structure it is a part of.
We're going to use CursorLoader
to query the Android device for a list of music albums available. Because CursorLoader
is already implemented to correctly handle all of the details of working with a Cursor
, we don't need to subclass it. We can simply instantiate it, passing in the information it needs in order to open the Cursor
it should manage for us. We can do this in the onCreateLoader
callback:
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String[] columns = new String[] { MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST, MediaStore...