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

  • Home
  • SEARCH
  • 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 9108941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:55:25+00:00 2026-06-17T02:55:25+00:00

I can Access Database function from my Activity and it works fine. But when

  • 0

I can Access Database function from my Activity and it works fine. But when I use the same in Broadcast receiver class it fails and gives me default value of cursor ,And my logcat shows this:

close() was never explicitly called on database
DatabaseObjectNotCloseException

I have also done

db = context.openOrCreateDatabase("blitz.db", 0, null);    
dh=new DataHelper(context);

and passed the context of onReceiver method to DataHelper Class.
It shows error on this line

OpenHelper openhelper=new OpenHelper(this.context);
this.db=openhelper.getWritableDatabase();

Please let me know where I am going wrong

  • 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-17T02:55:26+00:00Added an answer on June 17, 2026 at 2:55 am

    always close the database when you finished your database work,

    for simplicity create following method in your databaseHandler class ,

    public void Open_DB(SQLiteDatabase db){
       return this.getWritableDatabase();
        } 
    
    public void Close_DB(SQLiteDatabase db){
        db.close();
        }
    

    and use this methods in your activity or service as,

    OpenHelper openhelper=new OpenHelper(getApplicationContext());
     SQLiteDatabase db=openhelper.Open_DB(db)
    openhelper.some_Operation(db);
    db.Close_DB(db); 
    

    or you can open and close the database in your single mehod(which is in your database handler class) as

    public void deleteRecord(String id) {
            SQLiteDatabase db = this.getWritableDatabase();
            db.delete(TABLE_REMINDER, REMINDER_ID + " = ?",
                    new String[] { String.valueOf(id)});
            db.close();
        }
    

    and call this method from your activity as,

    public void Delete_A_Reminder(String id){
         DatabaseHandler mydb=new DatabaseHandler1(getApplicationContext());
         mydb.deleteRcord(id);
     }
    

    In general,if u want to open an window of your house which is already open before then you have to close it and again open it,in the same manner if your database is already opened and if you want to open it again then you have to close it first.so that you can open it again.

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

Sidebar

Related Questions

Can anyone give me some idea about uploading data from excel to access database
I got a combobox that is populated from a access database. How can I
In database.yml you define all the settings. How can I access those settings from
How can I call Access's Compact and Repair Database utility from within C++? I'm
I am getting the cursor value zero when i access it from Broadcast Receiver
How can I access function b from within function a? This is what I
In MongoLab you generate an API key and then anyone can access your database
can anyone tell me how to select data by date in MS.ACCESS database using
How can I get the field names of an MS Access database table? Is
I have a postgres database on my localhost I can access without a password

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.