Can you use a LoaderManager from a Service?

Does anyone know why LoaderManager was excluded from Service? As stated in the other answer, LoaderManager was explicitly designed to manage Loaders through the lifecycles of Acivities and Fragments. Since Services do not have these configuration changes to deal with, using a LoaderManager isn’t necessary. If not is there a way around this? Yes, the … Read more

Is it OK to have one instance of SQLiteOpenHelper shared by all Activities in an Android application?

Click here to see my blog post on this subject. CommonsWare is right on (as usual). Expanding on his post, here is some sample code that illustrates three possible approaches. These will allow access to the database throughout the application. Approach #1: subclassing `Application` If you know your application won’t be very complicated (i.e. if … 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.

android – CursorLoader & SQLite without Content Provider

The two implementations you mention in your post both offer all of the benefits of the CursorLoader except the ability to receive notifications when the underlying content changes. I’ve been looking into this a lot recently and I can confidently tell you that the Android API currently does not provide a means of doing this … Read more

getLoaderManager().initLoader() doesn’t accept ‘this’ as argument though the class (ListFragment) implements LoaderManager.LoaderCallbacks

You are not using the right implementations of CursorLoader and Loader. Remove your old imports and use these ones: import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; But I have the same Problem using SherlockActionBar: As I have to extend SherlockListActivity there is NO method getSupportLoadManager(). Any ideas on this? EDIT: follow this tutorial if … 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