java.lang.IllegalStateException: attempt to re-open an already-closed object On Orientation Change

ε祈祈猫儿з 提交于 2020-01-30 08:31:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!