2

I extend a my previous question, I resolve that issue but I have a new similar error.

I have the following activity

public class ActivityMatchesList extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor> {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ListView lvLive = (ListView)findViewById(R.id.matchListList);
        lvLive.setOnItemClickListener(OnItemClickListenerLive);
        getSupportLoaderManager().initLoader(1, null, this);
        getSupportLoaderManager().initLoader(2, null, this);
        getSupportLoaderManager().initLoader(3, null, this);
    }

    private OnItemClickListener OnItemClickListenerLive = new OnItemClickListener(){
        Intent i = new Intent(ActivityMatchesList.this, ActivityEvents.class);
        finish();
        startActivity(i); 
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) { //FIXME: add switch for 3 loader
        switch (id){
        case 1:
            CursorLoader cursorLoaderLive = new CursorLoader(this, uri1,null,null,null,null);
            return cursorLoaderLive;
        case 2:
            CursorLoader cursorLoaderRankingLeague = new CursorLoader(this, uri1,null,null,null,null);
            return cursorLoaderRankingLeague;
        case 3:
            CursorLoader cursorLoaderRankingLive = new CursorLoader(this, uri1,null,null,null,null);
            return cursorLoaderRankingLive;
        default:
            return null;
        }
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        switch (loader.getId()){
        case 1:
            Adapter1.swapCursor(cursor);
            break;
        case 2:
            Adapter2.swapCursor(cursor);
            break;
        case 3:
            Adapter3.swapCursor(cursor);
            break;
        }
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        switch (loader.getId()){
        case 1:
            Adapter1.swapCursor(null);
            break;
        case 2:
            Adapter2.swapCursor(null);
            break;
        case 3:
            Adapter3.swapCursor(null);
            break;
        }
    }
}

With OnItemClickListener I finish() this activity and start a new, when I finish the new to return to this sometimes I have the following error

11-30 09:35:01.839: INFO/dalvikvm(321): Uncaught exception thrown by finalizer (will be discarded):
11-30 09:35:01.848: INFO/dalvikvm(321): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@43c6ab00 on MAIN_TABLE that has not been deactivated or closed
11-30 09:35:01.848: INFO/dalvikvm(321):     at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
11-30 09:35:01.848: INFO/dalvikvm(321):     at dalvik.system.NativeStart.run(Native Method)

I am not able to discover the reason, someone can help me?

edit: the problem persist also if I use only 1 loader. It seems that with the activity finish the loader sometimes gon't close cursor, why?

crbin1
  • 2,219
  • 3
  • 22
  • 29

1 Answers1

0
  1. Why are you calling finish() in this activity before starting the new one? Android handles the activity life cycle. If it's because you don't want to return to this activity when the next activity finishes, consider noHistory instead.

  2. The error you posted means there's an open cursor that should have been closed. If you're seeing the error when you finish the new activity, it seems to indicate to me that the error is in the new activity, not this one. You may need to call Cursor.close() before finishing the new activity (perhaps in onPause()or onDestroy()).

My answer to your previous question may also be of some use: https://stackoverflow.com/a/8857179/399105

Community
  • 1
  • 1
bmaupin
  • 14,427
  • 5
  • 89
  • 94