In my DataBase Adapter I have a list of methods that puts data, upgrades data and retrieves data. In each method I Instatiate like this
SQLiteDatabase db = this.getWritableDatabase();
I used to close the database on every method and my app used to crash. Then I left them open in every method so the crashing stopped.
Does the line of code open several database connections when I use several methods with the same line?
Is there a better approach to open the database?
Here's one of my methods
public int getAntalRows() throws Exception {
SQLiteDatabase db = this.getWritableDatabase();
Cursor mCount= db.rawQuery("SELECT COUNT (*) FROM " + TABLE_PRODUCTS,
null);
mCount.moveToFirst();
int x= mCount.getInt(0);
mCount.close();
return x;
}