Where to close the SQLiteOpenHelper if i am using a singelton one
android
Solution
As there is no such "app is closed" event in Android by design. You either have to handle you database connection per `Activity` so you will know when you `Activity` gets destroyed or you have to somehow take care about which object uses the database helper and only close the helper when no other object is using the helper any more.
If you stay with the singleton solution be aware to pass an `Application` context to the `getDBHelper()` method and not a `Activity` context as this might lead to memory leaks.
Problem
i have the following class that permit user to get a `SQLiteOpenHelper` object ``` import android.content.Context; public class DBUtils { private DBUtils(){ } private static DBHelper dbHelper ; public static synchronized DBHelper getDBHelper(Context context){ if(dbHelper == null){ dbHelper = new DBHelper(context, ApplicationMetaData.DATABASE_NAME, null, ApplicationMetaData.DATABASE_VERSION); } return dbHelper; } public static synchronized void closeDBHelper(){ if(dbHelper!=null ) dbHelper.close(); dbHelper = null; } @Override protected Object clone() throws CloneNotSupportedException { // TODO Auto-generated method stub throw new CloneNotSupportedException(); } } ``` i want to know where should i `close` this singleton object i can't relay on the `onTerminate()` method since it will not be called . i want to close it when the user exit my app ? any solution for this