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; } }
source share