Confused about CursorLoaders and using them with a custom SQLiteOpenHelper
Asked Answered
A

1

6

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?

Augmented answered 31/5, 2012 at 23:2 Comment(1)
Thanks for this question. All their examples in documentation only show how to use cursors with the contacts, as if we all need the database just for that...Decomposition
R
4

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.

Rust answered 31/5, 2012 at 23:5 Comment(2)
Seems solid. Although importing the project from git caused Eclipse to throw up a compiler error about the @Override annotation in onSharedPreferenceChanged(). Still, I'll try it out.Augmented
@MowDownJoe: You need to set your Java compliance level to 1.6, instead of the 1.5 it is on now.Rust

© 2022 - 2024 — McMap. All rights reserved.