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.

AsyncTaskLoader vs AsyncTask

You can have a look at the compatibility library’s source code to get more info. What a FragmentActivity does is: keep a list of LoaderManager‘s make sure they don’t get destroyed when you flip your phone (or another configuration change occurs) by saving instances using onRetainNonConfigurationInstance() kick the right loader when you call initLoader() in … Read more

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

Using Singleton design pattern for SQLiteDatabase

Click here to see my blog post on this subject. Here is some sample code that illustrates three possible approaches. These will allow access to the database throughout the application. Approach #1: have `SQLiteOpenHelper` be a static data member This isn’t the complete implementation, but it should give you a good idea on how to … 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