Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6966535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:12:17+00:00 2026-05-27T16:12:17+00:00

I have an activity where I am opening an database by calling constructor of

  • 0

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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:12:17+00:00Added an answer on May 27, 2026 at 4:12 pm

    When you start a new Activity, the first Activity may or may not go through the various ‘exit’ stages but there is no guarantee which ones it will go through. It depends entirely on the available resources and other factors on an individual device.

    The first Activity might simply pause and when you return it will resume. However, the first Activity could very likely be stopped or even destroyed. There is no guarantee what the Android OS will do with the first Activity.

    In your case it seems the first IS actually being destroyed and re-created when you return from the second Activity.

    The only way to verify this is to override all of the methods such as onPause, onStop and onDestroy and have each of them use Log to show which stages the first Activity goes through.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have button and onClick I perform opening of a new activity like this:
I'm opening an Activity using this: startActivity(new Intent(Parent.this, Child.class)); And on the child, I
I have a function for opening a new activity, but I wan't to use
I have seen this code segment for opening a native activity that chooses one
I have an activity which shows some List entries. When I click on a
I have a notification which should give me some parameters when opening an activity
I am following this article to learn how to open new screen on button
I have a problem with progress dialog on opening an activity (called activity 2
i have an activity where i am opening a camera. i am using framelayout
On opening the activity, the user chooses an option from a spinner. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.