How to read an SQLite DB in android with a cursorloader?

Android Guide suggests to create a ContentProvider when you want to share your data with other applications. If you don’t need this, you can just override method loadInBackgroud() of the CursorLoader class. For example write like this in your onCreateLoader: return new CursorLoader( YourContext, null, YourProjection, YourSelection, YourSelectionArgs, YourOrder ) { @Override public Cursor loadInBackground() … Read more

Access ordered images and video in same Cursor

After lots of research and playing around with source code, I’m finally a bit more familiar with the Android filesystem. To get a single Cursor which can access information about both Images and Video I used the following: // Get relevant columns for use later. String[] projection = { MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.DATE_ADDED, MediaStore.Files.FileColumns.MEDIA_TYPE, MediaStore.Files.FileColumns.MIME_TYPE, MediaStore.Files.FileColumns.TITLE … Read more

CursorLoader not updating after data change

Did you call setNotificationUri(ContentResolver cr, Uri uri) on the Cursor before returning it in ContentProvider.query()? And did you call getContext().getContentResolver().notifyChange(uri, null) in the ‘insert’ method of your ContentProvider? EDIT: To get a ContentResolver call getContext().getContentResolver() in your ContentProvider.

Testing ViewPager (and CursorLoader) with Robolectric

I’m not certain, but I would wager that the internal code is trying to use an AsyncTask to invoke the cursor loader’s loadInBackground() method. You might be seeing a deadlock because the AsyncTask tries to invoke onPostExecute(). That call will try to run in your main UI thread, which happens to be the thread of … Read more

CursorLoader usage without ContentProvider

I wrote a simple CursorLoader that does not need a content provider: import android.content.Context; import android.database.Cursor; import android.support.v4.content.AsyncTaskLoader; /** * Used to write apps that run on platforms prior to Android 3.0. When running * on Android 3.0 or above, this implementation is still used; it does not try * to switch to the framework’s … Read more