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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:22:56+00:00 2026-06-18T23:22:56+00:00

Android 2.3.3 I have two activities in my application that access the database. Whenever

  • 0

Android 2.3.3

I have two activities in my application that access the database. Whenever I change the orientation of the mobile, i get the following errors in logcat, though the program does work. I understand from the errors that I have to call close() and close the database and cursors. But where do i put it exactly.

Will closing the database and cursors in onDestroy() of the activity, solves the issue?

    Database pm;
        Cursor c;

    @Override
        public void onDestroy() {
          pm.close();
          c.close();
          // Any other cursors that are used...

            super.onDestroy();
    }

Here is the logcat trace incase needed…

02-16 22:37:50.419: E/Database(602): close() was never explicitly called on database 'portfolio' 
02-16 22:37:50.419: E/Database(602): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
02-16 22:37:50.419: E/Database(602):    at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1849)
02-16 22:37:50.419: E/Database(602):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:822)
02-16 22:37:50.419: E/Database(602):    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:856)
02-16 22:37:50.419: E/Database(602):    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:849)
02-16 22:37:50.419: E/Database(602):    at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:553)
02-16 22:37:50.419: E/Database(602):    at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
02-16 22:37:50.419: E/Database(602):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
02-16 22:37:50.419: E/Database(602):    at com.xx.xxx.Database.<init>(Database.java:21)
02-16 22:37:50.419: E/Database(602):    at com.xx.xxx.Brokerage_Settings.onCreate(Brokerage_Settings.java:118)
02-16 22:37:50.419: E/Database(602):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-16 22:37:50.419: E/Database(602):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-16 22:37:50.419: E/Database(602):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-16 22:37:50.419: E/Database(602):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-16 22:37:50.419: E/Database(602):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-16 22:37:50.419: E/Database(602):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 22:37:50.419: E/Database(602):    at android.os.Looper.loop(Looper.java:130)
02-16 22:37:50.419: E/Database(602):    at android.app.ActivityThread.main(ActivityThread.java:3687)
02-16 22:37:50.419: E/Database(602):    at java.lang.reflect.Method.invokeNative(Native Method)
02-16 22:37:50.419: E/Database(602):    at java.lang.reflect.Method.invoke(Method.java:507)
02-16 22:37:50.419: E/Database(602):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
02-16 22:37:50.419: E/Database(602):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
02-16 22:37:50.419: E/Database(602):    at dalvik.system.NativeStart.main(Native Method)

What is the best practise to close the database and cursor objects?

  • 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-18T23:22:58+00:00Added an answer on June 18, 2026 at 11:22 pm

    Call close in onPause(). When you change orientation of mobile your app changes state and you are supposed to close database/cursor object before the super.onPause() is called by android system. Call close in onPause method before the command super.onPause().

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

Sidebar

Related Questions

I have an application that contains two Activities with <intent-filter> <action android:name=android.intent.action.MAIN/> <category android:name=android.intent.category.LAUNCHER/>
I have an Android application that contains two Activities . Activity A has a
I have two activities in an android application, each has a button that goes
I have an android application and while switching between two activities I want to
Say I have two Activities in an Android application, EditPerson and EditEmployee . It
I am trying do a simple application for Android . I have two Activities
I have two activities on my android application & at the second one, it
I'm new to the android .In my application i have two activities. In the
I'm trying to write an android application that has two main activities: login screen
I have two different activities in two packages as following: com.my.application.MyActivity1 com.my.application.Test.MyActivity2 In my

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.