dimanche 6 mars 2016

Why SQLite handling has to happen on activity or service class?

I am looking for a way to openOrCreateDatabase from another non-activity class and all tutorials and SO questions I found so far, are against that.

Why?

Method openOrCreateDatabase can be called only from Service or Activity or I can call it as a static method SQLiteDatabase.openOrCreateDatabase.

However, this method's second parameter, requires CursorFactory, which in most tutorials is: MODE_PRIVATE. I can't use MODE_PRIVATE from a non-activity class. Some suggest to use context.MODE_PRIVATE, but I wanted to avoid such dependency of passing a context from every activity that I want to use the DB.

What is the best way to have only one DB connection and DB handling in one class across all activities?

Aucun commentaire:

Enregistrer un commentaire