I have an activity where I am opening an database by calling constructor of SQLiteOpenHelper.
dbHelper = new DBHelper(this); //DBHelper class extends SQLiteOpenHelper
Then on click of a button I am opening another activity and closing the dbHelper.
int cuisineId = HelperUtils.getCuisineIdByName(dbHelper,cuisine);
SingletonGlobalClass.getInstance().setCuisineId(cuisineId);
String restaurantNameSearchStr = restaurantName.getText().toString().trim();
Intent intent = new Intent();
intent.setComponent(new ComponentName("ctnxa.android", ctnxa.android.SearchResultActivity"));
intent.putExtra("searchStr", restaurantNameSearchStr);
intent.putExtra("option", R.string.restaurant);
startActivity(intent);
dbHelper.close();
Now when I am pressing back button it comes back to this activity. When I am trying to click the search button again it uses the dbHelper and works as usually without any error. My expectation is it should not work as the dbHelper has already been closed before and it can only be re-instantiated when activity onCreate() method is called which is not getting called in this case as I am only pressing back button (It should call onResume()). I am really confused. Could any body explain what is happening here.
Edit: This is how I have implemented dbHelper.close()
@Override
public synchronized void close() {
super.close();
}