Skip to content Skip to sidebar Skip to footer

Illegalstateexception "attempt To Re-open An Already-closed Object" In Simplecursoradapter From Contentprovider

I have a series of ListView objects in Fragments that are being populated by a CursorAdapter which gets a Cursor from the LoaderManager for the activity. As I understand it, all d

Solution 1:

Have you updated your data set? It could be the case that the cursor has been re-loaded due notifying a change in the content resolver:

getContentResolver().notifyChange(URI, null);

If you have set a notification URI, this would trigger your current cursor to close and a new cursor to be returned by the cursor loader. You can then grab the new cursor if you have registered a onLoadCompleteListener:

mCursorLoader.registerListener(0, newOnLoadCompleteListener<Cursor>() {
    @OverridepublicvoidonLoadComplete(Loader<Cursor> loader, Cursor cursor) {
        // Set your listview's CursorAdapter
    }
});

Solution 2:

You can try to path null instead cursor into adapter constructor. Then owerride SwapCursor(Cursor c) in adapter, move initialization of cursor data there and call it in OnLoadFinished(Loader loader, Cursor data) method of your data loader.

enter code here
    @OverridepublicvoidonActivityCreated(Bundle savedInstanceState) {
    // ... building your query here
       mSimpleCursorAdapter = newmSimpleCursorAdapter(getActivity().getApplicationContext(),
           layout, null, from, to, flags);
    }

    @OverridepublicvoidonLoadFinished(Loader<Cursor> loader, Cursor data) {
       contentAdapter.swapCursor(data);
    }

Post a Comment for "Illegalstateexception "attempt To Re-open An Already-closed Object" In Simplecursoradapter From Contentprovider"