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 8218897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:57:41+00:00 2026-06-07T12:57:41+00:00

This title may sound a little bit crazy, but this is what is making

  • 0

This title may sound a little bit crazy, but this is what is making me confused. My app heavily uses local database operations. As suggested in the Android docs and some blogs, I extended the SQLiteOpenHelper class and defined all my DB operations there. As some of my DB operations execute in threads, opening and closing of the db causes some IllegalStateExceptions. So, I made my DB helper as Singleton and it resolved those issues, also getting rid of the open and close operations for every DB action. Now everything seems to be working fine even though I never close the DB.

  • My confusion is that is it necessary to close DB?
  • If so, what is the right place to do so, is it in onDestroy of the main activity or somewhere else?
  • If I don’t close DB, what are the side effects?
  • 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-06-07T12:57:43+00:00Added an answer on June 7, 2026 at 12:57 pm

    You can catch IllegalStateException if you’ll try to open again the same database.

    If you create instance of DBHelper in onCreate method of main activity – it would be write to close db in onDestroy. So, you can be sure, that next time in onCreate your database is not opened already.

    If you have reference to DBHelper in service, than it should be opened and closed in service, and not in activity.

    You can also use Application class for opening db, but than it will opened every time when you app starts (for example when you receive BroadcastReceiver)

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

Sidebar

Related Questions

Ok, the title may sound a little weird, but I think that kinda describe
The title may sound odd, but im kind of trying to set up this
I know the title may seem strange but this is what I want to
The title may seem a little weird but what I find around the internet
The title may sound confusing. But here's my issue. I want to show something
ok not as simple as title may make it sound. I tried this in
The title may sound a little strange, so I'll try to explain my problem:
The phrasing of the title may be a little confusing. I have an app
I understand the title may be a little vague, but, hopefully, I can explain
The question's title may sound stupid, but I have beenw wondering about the following

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.