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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:49:20+00:00 2026-06-05T10:49:20+00:00

I’ve read several related posts and even posted and answer here but it seems

  • 0

I’ve read several related posts and even posted and answer here but it seems like I was not able to solve the problem.

I have 3 Activities:
Act1 (main)
Act2
Act3

When going back and forth Act1->Act2 and Act2->Act1 I get no issues
When going Act2->Act3 I get no issues
When going Act3->Act2 I get occasional crashes with the following error: java.lang.IllegalStateException: trying to requery an already closed cursor android.database.sqlite.SQLiteCursor@.... This is a ListView cursor.

What I tried:
1. Adding stopManagingCursor(currentCursor);to the onPause() of Act2 so I stop managing the cursor when leaving Act2 to Act3

protected void onPause() 
{
    Log.i(getClass().getName() + ".onPause", "Hi!");

    super.onPause();
    saveState();

    //Make sure you get rid of the cursor when leaving to another Activity
    //Prevents: ...Unable to resume activity... trying to requery an already closed cursor
    Cursor currentCursor = ((SimpleCursorAdapter)getListAdapter()).getCursor();
    stopManagingCursor(currentCursor);
}
  1. When returning back from Act3 to Act2 I do the following:

    private void populateCompetitorsListView()
    {
    ListAdapter currentListAdapter = getListAdapter();
    Cursor currentCursor = null;
    Cursor tournamentStocksCursor = null;

    if(currentListAdapter != null)
    {
    currentCursor = ((SimpleCursorAdapter)currentListAdapter).getCursor();
    
    if(currentCursor != null)
    {
        //might be redundant, not sure
                    stopManagingCursor(currentCursor);
    
        // Get all of the stocks from the database and create the item list
        tournamentStocksCursor = mDbHelper.retrieveTrounamentStocks(mTournamentRowId);
                ((SimpleCursorAdapter)currentListAdapter).changeCursor(tournamentStocksCursor);
        }   
        else
        {
            tournamentStocksCursor = mDbHelper.retrieveTrounamentStocks(mTournamentRowId);
        }
    }
    else
    {
        tournamentStocksCursor = mDbHelper.retrieveTrounamentStocks(mTournamentRowId);
    }
    
        startManagingCursor(tournamentStocksCursor);        
    
        //Create an array to specify the fields we want to display in the list (only name)
        String[] from = new String[] {StournamentConstants.TblStocks.COLUMN_NAME, StournamentConstants.TblTournamentsStocks.COLUMN_SCORE};
    
        // and an array of the fields we want to bind those fields to (in this case just name)
        int[] to = new int[]{R.id.competitor_name, R.id.competitor_score};
    
        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter tournamentStocks = new SimpleCursorAdapter(this, R.layout.competitor_row, tournamentStocksCursor, from, to);
    
        //tournamentStocks.convertToString(tournamentStocksCursor);
        setListAdapter(tournamentStocks);       
    }
    

So I make sure I invalidate the cursor and use a different one. I found out that when I go Act3->Act2 the system will sometimes use the same cursor for the List View and sometimes it will have a different one.

This is hard to debug and I was never able to catch a crashing system while debugging. I suspect this has to do with the time it takes to debug (long) and the time it takes to run the app (much shorter, no pause due to breakpoints).

In Act2 I use the following Intent and expect no result:

protected void onListItemClick(ListView l, View v, int position, long id) 
{       
    super.onListItemClick(l, v, position, id);

    Intent intent = new Intent(this, ActivityCompetitorDetails.class);

    intent.putExtra(StournamentConstants.App.competitorId, id);
    intent.putExtra(StournamentConstants.App.tournamentId, mTournamentRowId);   

    startActivity(intent);
}

Moving Act1->Act2 Act2->Act1 never gives me trouble. There I use startActivityForResult(intent, ACTIVITY_EDIT); and I am not sure – could this be the source of my trouble?

I would be grateful if anyone could shed some light on this subject. I am interested in learning some more about this subject.

Thanks,D.

  • 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-05T10:49:21+00:00Added an answer on June 5, 2026 at 10:49 am

    I call this a 2 dimensional problem: two things were responsible for this crash:
    1. I used startManagingCursor(mItemCursor); where I shouldn’t have.
    2. I forgot to initCursorAdapter() (for autocomplete) on onResume()

    //@SuppressWarnings("deprecation")
    private void initCursorAdapter()
    {
        mItemCursor = mDbHelper.getCompetitorsCursor("");      
        startManagingCursor(mItemCursor); //<= this is bad!
    
        mCursorAdapter = new CompetitorAdapter(getApplicationContext(), mItemCursor);       
    
        initItemFilter();
    }
    

    Now it seems to work fine. I hope so…

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.