I've noticed that there are several question on this exception. But they do not solve my problem.
I have a databaseHelper class that has a inner class that extends SQLiteOpenHelper:
private static class OpenHelper extends SQLiteOpenHelper {
OpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w("DBHELPER", "Upgrading database");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
I have a service that updates the db continuously. And a activities that fetches data from the db .
In both the service and the activities the dbHelper get created:
this.dh = new DatabaseHelper(this);
And I do get the DatabaseObjectNotClosedException. Do I need to close the DatabaseHelper? How would I do that? Or how do I solve this problem?