How can I make SQLite Database Context null in OnDestroy () in Android?

I call the SQLite database method in my work. I cited the following code final DatabaseHandler db=new DatabaseHandler(Lists.this);to create an instance of the database in my Activity.I did not give the above code inside OnCreate (). I want the context to be null when calling the OnDestroy method. I have done the following:

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    System.gc();
    details.clear();
    DatabaseHandler db=new DatabaseHandler(null);

}

Is this the right way to make the context null?

+4
source share
3 answers

try it

DatabaseHandler db=null;

instead

DatabaseHandler db=new DatabaseHandler(null);
+1
source

When your activity is destroyed, its member variables are also destroyed. No need to manually try to reset them.

+1
source

Db

db.close();

+1

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


All Articles