java.lang.IllegalStateException: 尝试在方向改变时重新打开一个已经关闭的对象
java.lang.IllegalStateException: attempt to re-open an already-closed object On Orientation Change
我使用的是 1 Activity,在 sw600-land 的情况下膨胀 2 个碎片(2 个窗格),在 sw600 的情况下膨胀 1 个碎片
两个片段都实现了LoaderManager.LoaderCallbacks
我正在通过(在 onStart
中)
初始化加载程序
getActivity().getSupportLoaderManager().initLoader(pm2_MAIN_LOADER_ID, null, this);
然后我在 onLoadFinished
中关闭了光标(在它的最后一行)给我错误所以我试图在其他地方关闭它作为我在 Whosebug 上找到的答案 onDestroy
给出同样的错误
那么我什么时候可以关闭光标?
在 Loader
框架中使用 CursorLoader
时,您自己不应 close()
Cursor
。 CursorLoader
会处理它。
虽然 CursorLoader
的文档没有特别提到这一点,Loaders note it under Using the LoaderManager Callbacks 的一般文档在 onLoadFinished 部分。
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.
我使用的是 1 Activity,在 sw600-land 的情况下膨胀 2 个碎片(2 个窗格),在 sw600 的情况下膨胀 1 个碎片
两个片段都实现了LoaderManager.LoaderCallbacks
我正在通过(在 onStart
中)
getActivity().getSupportLoaderManager().initLoader(pm2_MAIN_LOADER_ID, null, this);
然后我在 onLoadFinished
中关闭了光标(在它的最后一行)给我错误所以我试图在其他地方关闭它作为我在 Whosebug 上找到的答案 onDestroy
给出同样的错误
那么我什么时候可以关闭光标?
在 Loader
框架中使用 CursorLoader
时,您自己不应 close()
Cursor
。 CursorLoader
会处理它。
虽然 CursorLoader
的文档没有特别提到这一点,Loaders note it under Using the LoaderManager Callbacks 的一般文档在 onLoadFinished 部分。
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 callclose()
on it yourself. If the cursor is being placed in aCursorAdapter
, you should use theswapCursor()
method so that the oldCursor
is not closed.