I'm searching info about SQLite on Android, and read some chapters of some books on Android Programming, but I don't know how to really use SQLite on Android correctly.
I'm developing an app that has Activities, Services and BroadcastReceivers, and all of them must read and write data in the database. So I have some questions:
- Where is the best place to create the
SQLiteOpenHelper
instance? I read about this, and it seems that the best way is to have onlySQLiteOpenHelper
for all the app. - When, and where, do I need to get
SQLiteDatabase
object by callingdbHelper.getReadableDatabase()
(orgetWritableDatabase
)? I need to do it on each query, closing it after each query? - I read that I should never do database operations in the main thread, so I'm creating an Async task for each database operation I do in an Activity, is this the best way?