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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:35:39+00:00 2026-06-01T08:35:39+00:00

I was advised in a previous question that I didn’t need to maintain the

  • 0

I was advised in a previous question that I didn’t need to maintain the database if the device is rotated as it uses a local database.

I thought that I could at least maintain the datasource for my List. I am having problems trying to do this because I get an error saying close() was not called on the database. I am calling close in the onDestroy though.

Can anyone see where I am going wrong here? I just want to improve the users experience by maintaining the data to repopulate the list after they rotate the device.

The other thing that is confusing me is my log statements come out in following order:

  • onCreate flights
  • first setup
  • reusing datasource
  • destroying activity

I would have expected the destroying activity to happen before reusing datasource.

package com.testing.flights;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.util.Log;
import android.widget.SimpleCursorAdapter;

public class FlightListActivity extends ListActivity {

private SQLiteDatabase database;
private String fields[] = {BaseColumns._ID, "name", "flights", "distance"};
private SimpleCursorAdapter datasource;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(ACTIVITY_SERVICE, "onCreate flights");

    datasource = (SimpleCursorAdapter) getLastNonConfigurationInstance();

    if (datasource == null) {
        database = getData();
        datasource = getCursor();
        Log.v(ACTIVITY_SERVICE, "first setup");
    }

    setListAdapter(datasource);
}

protected SQLiteDatabase getData() {
    DataBaseHelper myDbHelper = new DataBaseHelper(this.getApplicationContext());
    return myDbHelper.openDataBase();
}

protected CustomCursorAdapter getCursor() {
    Cursor data = database.query("pilots", fields, null, null, null, null, null);   
    final CustomCursorAdapter mysource = new CustomCursorAdapter(this, R.layout.row, data, fields, new int[] { R.id.id, R.id.name, R.id.flights, R.id.distance });
    return mysource;
}

@Override
public Object onRetainNonConfigurationInstance() {
    Log.v(ACTIVITY_SERVICE, "reusing datasource");
    final SimpleCursorAdapter myData = datasource;
    return myData;
}

@Override
protected void onDestroy() {
    Log.v(ACTIVITY_SERVICE, "destroying activity");
    database.close();
    super.onDestroy();
}

}

LogCat:

04-03 16:22:55.900: E/SQLiteDatabase(1860): close() was never explicitly called on database '/data/data/com.testing.flights/databases/club' 
  • 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-01T08:35:40+00:00Added an answer on June 1, 2026 at 8:35 am

    I believe what is happening is that the OS is prioritizing the creation of the new Activity over the destruction of the old one. Because onDestroy is not guaranteed to run (it can be killed) it is typical to open your database in onResume(), and to clean up after yourself in the onPause() method. (onPause won’t be killed, at least in honeycomb + ). As a result of what you have now, the new activity is trying to open a database that’s already open (is my guess). Not having tried to retain a cursor like this, I’m not 100% that this will fix your problem, but using that part of the lifecycle is the normal case for non view setup type things.

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

Sidebar

Related Questions

People always advised me that if I am doing some application that should use
After asking this question I was advised not to check in binaries into subversion.
My understanding is that it's advised testers are separate from developers, i.e you obviously
In GWT javadoc, we are advised If you only need a simple label (text,
Thanks @dtb for help, he advised really need piece of code for generic service
I have recently been advised that for my current rails app relationships I should
In a previous post, I was advised to use a DataTemplate to render a
HI I have made a maintenance package in that have used shrink database task
Somebody advised me to use Entity Framework here when I asked this question: what
I have been advised that having expose_php = On in my php.ini is a

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.