Should I call .close () on both SQLiteDatabase and SQLiteOpenHelper

SQLiteOpenHelper dbOpenHelper = new (ctx, nameofdb); SQLiteDatabase db = dbOpener.getWritableDatabase(); 

Do I need to call .close() on both of them, or is one of them enough? If so, which one?

 SQLiteDatabase SQLiteOpenHelper 

The problem I am facing is that I do not see one specific line in the DDMS view in Eclipse, but when I use the cursor to get it, it shows that I have this entry. So I think that this could be caused by the incorrect closing of the database? Anyone who can help will be wonderful. Thank you

+6
source share
1 answer

If you look at the docs for SQLiteOpenHelper.close () ...

public synchronized void close ()

Close any open database object.

It does not close SQLiteOpenHelper , it closes the database.

In addition to this, if you get the correct code, you can directly access the database object directly.

For example, if you have a query that you regularly use to get the cursor so that the adapter fills the view, create a method in your SQLiteOpenHelper class and put the query in it.

In other words, don't get the link to the actual database in your main code, just get SQLiteOpenHelper to do everything for you.

+5
source

Source: https://habr.com/ru/post/907537/


All Articles