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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:58:49+00:00 2026-05-19T12:58:49+00:00

I am trying to make my app rotation friendly, but I am having some

  • 0

I am trying to make my app rotation friendly, but I am having some problems saving the cursor.

The cursor holds about 13k+ rows of data displayed in a ListView, and thus would take quite a while if I would do a requery every time the configuration changes. In my onRetainNonConfigurationInstance(), I am returning my Cursor and then retrieving it through getLastNonConfigurationInstance().

However, my retrieved cursor seems to be closed already, and thus my adapter cannot render the list anymore. From what I understand, the cursor was closed since onDestroy() automatically closes all cursors.

I save the Cursor like this:

@Override
public Object onRetainNonConfigurationInstance() {
    return myCursor;
}

And retrieve it like this:

myCursor = (Cursor)getLastNonConfigurationInstance();
if (myCursor == null) {
    // Do some stuff here (access DB, etc)
} else { // we are returning from configuration change
    // Feed the cursor to the adapter
}

I am pasting the stack trace if someone wants to look at it:

01-25 16:57:45.637: ERROR/AndroidRuntime(12976): android.database.StaleDataException: Access closed cursor
    01-25 16:57:45.637: ERROR/AndroidRuntime(12976):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:217)
    01-25 16:57:45.637: ERROR/AndroidRuntime(12976):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
    01-25 16:57:45.637: ERROR/AndroidRuntime(12976):     at com.test.sample.helper.DictionaryAdapter.bindView(DictionaryAdapter.java:35)
[........More ListView-related errors here..........]

I stepped through the code and I found out that as far as onRetainNonConfigurationInstance(), the cursor is still open, but after getting it through getLastNonConfigurationInstance() it is already closed.

How can I make my Cursor survive the orientation change? Thank you for the help!

EDIT:
Based on Romain’s answer, I commented out all my startManagingCursor()s. I should have connected the dots and thought about it! Anyway, my app now survives one rotation, but flipping it back to the original orientation still crashes it. Continuing my debugging and will let you know what I find out.

EDIT2:
I think I may have found what is causing the new errors. I have implemented a FilterQueryProvider which returns a new Cursor. What I did was assign the results of that filter to my original Cursor. Seems to work so far.

  • 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-19T12:58:50+00:00Added an answer on May 19, 2026 at 12:58 pm

    You are probably using a managed cursor. Managed cursors are automatically closed when the Activity is destroyed. You should switch to an unmanaged Cursor.

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

Sidebar

Related Questions

Im trying to make an app with geoDjango but I'm actually having some problem
I am trying to make App Distribution from Facebook for android apps. But the
I'm trying to make an app that handles orientation/rotation similarly to the way the
I'm trying to make an app which compatible with 3.x and 4.x iOS. But
I am trying to make my app more tablet-friendly, and so I'm trying to
I'm trying to make an app where a user inputs some information and then
I am trying to make my app work for all devices, but I am
I'm trying to make an app to control some hi-fi over TCP and have
I'm trying to make an app that has three tabs, each with different but
I'm trying to make some app that will play the stream from wowza. That

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.