Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GlennReilly/4b825f83fb8e8d0ca8615149f66046c2 to your computer and use it in GitHub Desktop.
Save GlennReilly/4b825f83fb8e8d0ca8615149f66046c2 to your computer and use it in GitHub Desktop.
How to read an SQLite DB in android with a cursorloader?
Android Guide suggests to create a ContentProvider when you want to share you data with other applications. If you don't need this, you can just override method loadInBackgroud() of the CursorLoader class. For example write in you onCreateLoader:
return new CursorLoader( YourContext, null, YourProjection, YourSelection, YourSelectionArgs, YourOrder )
{
@Override
public Cursor loadInBackground()
{
// You better know how to get your database.
SQLiteDatabase DB = getReadableDatabase();
// You can use any query that returns a cursor.
return DB.query( YourTableName, getProjection(), getSelection(), getSelectionArgs(), null, null, getSortOrder(), null );
}
};
//from http://stackoverflow.com/questions/18326954/how-to-read-an-sqlite-db-in-android-with-a-cursorloader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment