Release ORMLite Assistant on @Singleton

I have a @Singleton class where I injected an instance of OrmLiteSqliteOpenHelper . Should I ever call OpenHelperManager.releaseHelper() ? In the case when I do this, where and how should this be done, since the class does not extend the Android base class, where could I get to onDestroy ?

+4
source share
1 answer

There is an ORMLite project of an Android project that demonstrates this as HelloAndroidNoBase . I would check it out.

The corresponding section of code from the main Activity shown below. You will need to have such code in each of your Activity or other classes that use the database.

If your class does not have the onDestroy() method, you need to add it and call it from one of the other classes that has onDestroy() . Main Activity is a good place to do it. This way your MainActivity.onDestroy() will call yourClass.onDestroy() when the application closes.

 public class HelloNoBase extends Activity { private DatabaseHelper databaseHelper = null; @Override protected void onDestroy() { super.onDestroy(); if (databaseHelper != null) { OpenHelperManager.releaseHelper(); databaseHelper = null; } } private DatabaseHelper getHelper() { if (databaseHelper == null) { databaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class); } return databaseHelper; } } 
+3
source

All Articles