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

How do CursorLoader automatically updates the view even if the app is inactive?

I found the answer for my question. In general, CursorLoader doesn’t automatically detect data changes and load them to view. We need to track URI for changes. This can be done by following steps: Registering an Observer in content resolver through cursor using: (Done in the query method of ContentProvider) cursor.setNotificationUri(getContext().getContentResolver(), uri); Now when there … 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.

AlphabetIndexer with Custom Adapter managed by LoaderManager

So I finally got this to work. Here’s how i did it: I added: ListView lv = getListView(); lv.setFastScrollEnabled(true); lv.setScrollingCacheEnabled(true); to the onLoadFinished() method after the new cursor was swapped in like so public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take care of closing the // … Read more

SimpleCursorTreeAdapter and CursorLoader for ExpandableListView

So i figured out that I needed to map loaderids to groupPositions and this solved my issue: Here is my Fragment class which implements the CursorLoader public class GroupsListFragment extends ExpandableListFragment implements LoaderManager.LoaderCallbacks<Cursor> { private final String DEBUG_TAG = getClass().getSimpleName().toString(); private static final String[] CONTACTS_PROJECTION = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; private static final … 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