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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:19:43+00:00 2026-05-31T13:19:43+00:00

My Activity contains this code to get all images on the SD card: String[]

  • 0

My Activity contains this code to get all images on the SD card:

String[] projection = {MediaStore.Images.Media._ID,
                       MediaStore.Images.Media.DATA,
                       MediaStore.Images.ImageColumns.DATA};  
Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                             projection, null, null,
                             MediaStore.Images.Media._ID); 
int count = cursor.getCount();
int image_path_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
int i;
for(i = 0; i < count; i++) {
    cursor.moveToPosition(i);
    String p = cursor.getString(image_path_index);
    fd.addToPhonePhoto(p);
}
cursor.close();

The occurred while the Activity was resuming:

03-14 14:06:48.380: E/AndroidRuntime(20793): java.lang.RuntimeException: Unable to resume activity {}: java.lang.RuntimeException: Unable to resume activity {}: android.database.StaleDataException: Attempted to access a cursor after it has been closed.

It only occurs on Android 4.0. If on Android 2.x or 3.x, it works normally. But if I change the system setting which selects the “don’t keep Activities” option in “Developer options”.
The error does not show.

I want to modify my code to avoid this error without changing the system setting. How should I do it?

  • 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-31T13:19:44+00:00Added an answer on May 31, 2026 at 1:19 pm

    I think this is because of the managedQuery call + you closing the cursor. From the docs of the managedQuery() method:

    Warning: Do not call close() on a cursor obtained using this method,
    because the activity will do that for you at the appropriate time.
    However, if you call stopManagingCursor(Cursor) on a cursor from a
    managed query, the system will not automatically close the cursor and,
    in that case, you must call close().

    Leave the cursor for the Android system to manage and don’t call cursor.close();.

    Note: The managedQuery method is deprecated and it should be avoided, implement CursorLoaders instead. More info about CursorLoaders can be found at developer.android.com.

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

Sidebar

Related Questions

I Have activity that get some data from the internet, and shows it to
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have a launcher activity which contains two tabs which corresponds to two separate
I have some problem with Android AsyncTask. There is an Activity which contains some
I have a service that also contains an activity the problem is sometimes it
I have a workflow that contains a Pick activity. Each PickBranch is triggered by
I currently have a class called clientActivity that contains a finger paintig activity that
I'm using TabActivity with Custom Title. TabControl.xml contains android:focusable=true android:focusableInTouchMode=true When activity gets launched,
I am trying to show a customizable dialog. This dialog contains 3 edittext and
i have 4 tab with activity group..all tab contain list of item and on

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.