android: android.database.StaleDataException
===

I wanted to post my code here but it was too big and spaghetti code to post on here.

I will try to explain my situation here: Currently I received an error saying : Attempted to access a cursor after it has been closed. This messaged only received when I either pressing back button to previous activity or resuming the application. I suspected one of the code that will cause this problem and this was my custom gridview. I tried alot of tricks to solve it but no luck to fix it.

Since I knew that the cause of the problem was the gridview on one of the layout that i added at runtime. Therefore, I tried removed the custom gridview in onPause and reCreate it in onResume. Assuming the custom gridview may have some cursor that hanging around that cause this issue. So remove the gridview and recreate it to see whether I can hack to solve the problem. It didn't work as expected. I thought if it's been removed, and recreate the gridview object will have fresh copy of it so that way i can solve my problem.

This is the code I have remove the grid at the onPause:

    LinearLayout layout = (LinearLayout) findViewById(R.id.thumbnail_grid);
	    LinearLayout.LayoutParams params =  new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
	    params.weight = 1.0f;
    
	layout.removeAllViews();


This is the code I have re-create the grid at the onResume:

        LinearLayout layout = (LinearLayout) findViewById(R.id.thumbnail_grid);
	    LinearLayout.LayoutParams params =  new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
	    params.weight = 1.0f;
    
	    grid = new ThumbnailGridView(this, this.getBaseContext());
        grid.setOnScrollListener(scrollChanged);
        grid.setWillNotDraw(false);
        grid.setId(R.id.imageView1);
        
        layout.addView(grid,params);

I have commented the creation of the grid part and found that it was the problem caused my application to crash. 