java.lang.IllegalStateException:尝试在方向更改时重新打开一个已经关闭的对象 [英] java.lang.IllegalStateException: attempt to re-open an already-closed object On Orientation Change

查看:135
本文介绍了java.lang.IllegalStateException:尝试在方向更改时重新打开一个已经关闭的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用1个活动,在sw600-land情况下会膨胀2个片段(2个窗格),在sw600情况下会膨胀1个片段

I am using 1 Activity that inflates 2 fragments (2 panes) in case of sw600-land and 1 fragment case of sw600

两个片段都实现了LoaderManager.LoaderCallbacks

both of the fragments implements LoaderManager.LoaderCallbacks

我正在( onStart 中)初始化加载程序

I'm initializing loader by (in onStart)

getActivity().getSupportLoaderManager().initLoader(pm2_MAIN_LOADER_ID, null, this);

然后我关闭了 onLoadFinished (在它的最后一行)中的游标,给了我错误,因此我尝试将其关闭,作为我在StackOverflow上找到的答案,onDestroy 给出相同的错误

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?

推荐答案

Loader 框架中使用 CursorLoader 时,不应 close()您自己的 Cursor . CursorLoader 将对其进行处理.

When using a CursorLoader with the Loader framework, you should not close() the Cursor yourself. The CursorLoader will handle it.

尽管 CursorLoader 的文档没有特别提及,但是加载器使用LoaderManager回调下进行记录,在 onLoadFinished 部分.

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.

一旦知道应用程序不再使用数据,加载程序将释放数据.例如,如果数据是来自 CursorLoader 的游标> ,您不应调用 close() 放在自己身上.如果将光标放置在 CursorAdapter ,则应使用 <代码> swapCursor() 方法,这样旧的 Cursor 没有关闭.

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.

这篇关于java.lang.IllegalStateException:尝试在方向更改时重新打开一个已经关闭的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆