I have following class \"Singleton\" to handle SQLite connection and to make sure to have 1 instance of connection for whole process/app:
public class DBCon
In your Application class
public static SQLiteDatabase database;
@Override
public void onCreate() {
super.onCreate();
SQLiteOpenHelper helper = Database.getInstance(getApplicationContext());
if (database == null) {
database = helper.getWritableDatabase();
} else {
if (!database.isOpen()) {
database = helper.getWritableDatabase();
}
}
}
In your queries class
public DataSources() {
database = ApplicationController.database;
}
That way you create a writeable db object once