问题
I am using 1 Activity that inflates 2 fragments (2 panes) in case of sw600-land and 1 fragment case of sw600
both of the fragments implements LoaderManager.LoaderCallbacks
I'm initializing loader by (in onStart)
getActivity().getSupportLoaderManager().initLoader(pm2_MAIN_LOADER_ID, null, this);
then I closed the cursor in onLoadFinished(at the last line of it) giving me the error so I have tried to close it somewhere else as the answers that I found on StackOverflow as onDestroy giving the same error
so when I can close the cursor?
回答1:
When using a CursorLoader with the Loader framework, you should not close() the Cursor yourself. The CursorLoader will handle it.
Though the docs for CursorLoader don't specifically mention this, the general docs for Loaders note it under Using the LoaderManager Callbacks, in the onLoadFinished section.
The loader will release the data once it knows the application is no longer using it. For example, if the data is a cursor from a CursorLoader, you should not call close() on it yourself. If the cursor is being placed in a CursorAdapter, you should use the swapCursor() method so that the old Cursor is not closed.
来源:https://stackoverflow.com/questions/45892049/java-lang-illegalstateexception-attempt-to-re-open-an-already-closed-object-on