Database open / closed - database not open

In each Activity, I added the onCreate()following lines in the method :

database = new DatabaseHelper(this);  
database.open();

And in each method the onDestroy()following line:

database.close();

Thus, until the activity is destroyed, the database will be open.

Sometimes some users get power if my application wants to update something in the database.

Following error:
java.lang.IllegalStateException: database not open
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1776)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1731)

How can this happen? If I open the database in onCreate()and close it in onDestroy()If it always opens ?!

+3
source share
1 answer

Binnyb , , onDestroy, . / , / .

UPD:

google dev docs, getWritableDatabase , db .

+3

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


All Articles