I have an app that works fine on all recent versions of android up to
and including gingerbread.  When testing on honeycomb however,  I'm
getting the following exception when restarting an activity that uses
managed cursors.

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {com.xxxxx.MyApp/
xxxxx.MyApp.MyActivity}: java.lang.IllegalStateException: trying to
requery an already closed cursor
    at
android.app.ActivityThread.performResumeActivity(ActivityThread.java:
2215)
    at
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:
2243)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
1019)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:126)
    at android.app.ActivityThread.main(ActivityThread.java:3997)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: trying to requery an
already closed cursor
    at android.app.Activity.performRestart(Activity.java:4343)
    at
android.app.ActivityThread.performRestartActivity(ActivityThread.java:
2640)
    at
android.app.LocalActivityManager.moveToState(LocalActivityManager.java:
163)
    at
android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:
518)
    at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
    at xxxxx.MyApp.MyActivity.onResume(MyActivity.java:57)
    at
android.app.Instrumentation.callActivityOnResume(Instrumentation.java:
1153)
    at android.app.Activity.performResume(Activity.java:4374)
    at
android.app.ActivityThread.performResumeActivity(ActivityThread.java:
2205)
    ... 10 more

Has anybody else come across this?  I realise that the Activity
methods for cursor management (managedQuery, startManagingCursor and
stopManagingCursor) have been deprecated in honeycomb in favour of the
new CursorLoader class, but I would have expected backward
compatibility to be preserved.

The specific details for replicating the issue are:
The main activity is a tabbed activity, with tab content provided by
sub-activities.  One of the sub activities is an
ExpandableListActivity with data provided by cursors (one cursor for
the group list, another for children).  Initially all groups are
collapsed.  If I open a new activity (eg Settings via a menu option)
while viewing this tab before expanding any groups, then exit the new
activity returning to the tab with the collapsed groups, everything is
fine.  If, however, I expand one or more of the groups before opening
a new activity, then when I return the above exception is triggered.
Interestingly, if I expand a group then collapse it again, then launch
a new activity with all groups collapsed, the exception *is*
triggered.  The mere fact that a group was expanded (even if
subsequently collapsed) is enough to trigger the "trying to requery an
already closed cursor" exception during restart of the main activity.
Note: the issue is NOT triggered by merely triggering the pause/resume
activity lifecycle methods.  It only happens if the main activity is
stopped and restarted (calling onRestart(), onStart() and then
onResume()).

Does anyone know what is likely to be causing this and if an easy fix
is available?  I would prefer not to refactor my code to use the new
CursorLoader framework as my app needs to work on pre-honeycomb
versions.  To use the new API would mean doing so via reflection -- I
don't want to go there if I can help it.

Thanks in advance ...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to