androidandroid-cursorandroid-3.0-honeycomb

Honeycomb and cursors


I have this activity that was completely converted to use honeycomb. I reworked all the cursor management to use the new cursorLoader. Everything works great on all other os versions (using the compatibility library), but still does not work on honeycomb. The following stack trace is extremely difficult to understand because it does not tell me which cursor or which line is failing. Furthermore, when debugging, no line of code in ParentActivity is ever executed. This error is happening when I resume the ParentActivity. Works great when I start the activity but fails when returning to it.

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

Solution

  • This is the effect of some changes that were made in Honeycomb to how Cursors are managed. Previously if you called startManagingCursor more than once everything continued to work normally, now it will causes an IllegalStateException because the activity is trying to requery a closed cursor. The solution is to close the old cursor before calling startManagingCursor again (Like when swapping cursors).

    So your ParentActivity is doing this indirectly as a result of the managed cursor lifecycle inside an Activity.

    Now you mentioned your were using the ACL and CursorLoader, make sure you are calling swapCursor(Cursor c) when changing cursors and this should fix your issues.

    You can see some of the discussion of this here: http://groups.google.com/group/android-developers/browse_thread/thread/658133bec901d7e