Mic*_*tle 4 android cursor android-3.0-honeycomb
我有这个活动完全转换为使用蜂窝.我重新设计了所有游标管理以使用新的cursorLoader.所有其他操作系统版本(使用兼容性库)的一切都很好用,但仍不适用于蜂窝.以下堆栈跟踪非常难以理解,因为它不会告诉我哪个光标或哪个行失败.此外,在调试时,不会执行ParentActivity中的任何代码行.恢复ParentActivity时会发生此错误.当我开始活动时工作得很好但返回时却失败了.
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): FATAL EXCEPTION: main
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): java.lang.RuntimeException: Unable to resume activity {com.xxx.xxx/com.xxx.xxx.ParentActivity}: java.lang.IllegalStateException: trying to requery an already closed cursor
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2227)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2255)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1028)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.os.Looper.loop(Looper.java:132)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.app.ActivityThread.main(ActivityThread.java:4025)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at java.lang.reflect.Method.invokeNative(Native Method)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at java.lang.reflect.Method.invoke(Method.java:491)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at dalvik.system.NativeStart.main(Native Method)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): Caused by: java.lang.IllegalStateException: trying to requery an already closed cursor
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.app.Activity.performRestart(Activity.java:4394)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.app.Activity.performResume(Activity.java:4420)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2217)
05-29 17:23:32.978: ERROR/AndroidRuntime(31692): ... 10 more
Run Code Online (Sandbox Code Playgroud)
dav*_*idk 11
我遇到了同样的问题.这就是我所做的.在我称之为startManagingCursor的所有活动中,我将其覆盖为:
@Override
public void startManagingCursor(Cursor c) {
// To solve the following error for honeycomb:
// java.lang.RuntimeException: Unable to resume activity
// java.lang.IllegalStateException: trying to requery an already closed cursor
if (Build.VERSION.SDK_INT < VersionUtil.HONEYCOMB) {
super.startManagingCursor(c);
}
}
Run Code Online (Sandbox Code Playgroud)
这使我的应用程序在Honeycomb和早期版本上正确运行.
我有同样的问题,并认为我可能已经找到了问题和一个"干净"的修复.(我认为停止管理游标并不是一个好主意)
我在一些活动中使用Adapter.changeCursor,除了蜂窝以外,所有版本都运行良好.changeCursor方法关闭旧游标,但显然不会停止管理该游标.因此,活动继续管理已关闭的旧游标.在重新启动活动时,它会尝试重新查询它,而不检查它是否已关闭.
所以我的解决方案是:
Cursor oldCursor = mAdapter.getCursor();
mAdapter.changeCursor(newCursor);
stopManagingCursor(oldCursor);
Run Code Online (Sandbox Code Playgroud)
到现在为止,我再也无法重现异常.
| 归档时间: |
|
| 查看次数: |
4825 次 |
| 最近记录: |