Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about CursorLoaders and using them with a custom SQLiteOpenHelper

I'm writing an app that allows people to set alarms for various tasks that they need to do. My current plan is to store all the relevant data into an SQLite database. To that end, I have created a class that extends SQLiteOpenHelper and filled it with methods to handle all the CRUD that I'd expect to have to take in. Knowing that it's generally a bad idea to do all the processing on one thread, I looked up ways to separate the work between threads and found CursorLoader and LoaderManager, which seemed ideal as they were available in the Android Compatibility Library. However, LoaderManager seems to require a ContentProvider going by the tutorial in the documentation, and I haven't really seen a need to do anything with ContentProviders since I wasn't planning on allowing other apps to access the data. Without a ContentProvider, I don't know how I'm supposed to get a Uri for my databases to feed into the CursorLoader. Is there a way for me to keep using my class that extends SQLiteOpenHelper and still implement LoaderManager to allow me to keep all the populating ListFragments with my cursor off of the UI thread?

like image 394
MowDownJoe Avatar asked May 31 '12 23:05

MowDownJoe


1 Answers

Is there a way for me to keep using my class that extends SQLiteOpenHelper and still implement LoaderManager to allow me to keep all the populating ListFragments with my cursor off of the UI thread?

You just need a different Loader implementation, one that does not involve a ContentProvider. It just so happens that I wrote one of those.

like image 196
CommonsWare Avatar answered Oct 06 '22 13:10

CommonsWare