That's a reasonable idea, thanks. Right now, I'm calling changeCursor
(null) for each of my adapters in onDestroy(), but if I run into
trouble with leaking cursors before I can set them into an adapter
I'll try removing the listeners.

Filed at http://code.google.com/p/android/issues/detail?id=2174.

On Mar 7, 6:04 pm, Marco Nelissen <marc...@android.com> wrote:
> One possible workaround that comes to mind is to remove your listener
> in your activity's onPause or onStop, so that it won't fire anymore
> when the activity is shutting down. Though having to add extra code to
> make managed cursors work for you kind of defeats the purpose, I
> suppose.
> Can you please file a bug athttp://b.android.com?
>
> On Sat, Mar 7, 2009 at 4:50 PM, Jeffrey Yasskin <jyass...@gmail.com> wrote:
>
> > Activity.performStop() contains the following loop (around line 3394
> > in the 1.0 SDK release and at
> >http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;...
>
> >            final int N = mManagedCursors.size();
> >            for (int i=0; i<N; i++) {
> >                ManagedCursor mc = mManagedCursors.get(i);
> >                if (!mc.mReleased) {
> >                    mc.mCursor.deactivate();
> >                    mc.mReleased = true;
> >                }
> >            }
>
> > In my app, mc.mCursor.deactivate() calls (indirectly)
> > SimpleCursorAdapter.notifyDataSetInvalidated(), which calls
> > (indirectly) AdapterView.fireOnSelected(), which calls my
> > OnItemSelectedListener, which calls stopManagingCursor(), which
> > reduces the size of mManagedCursors, which makes the ArrayList.get()
> > call throw on the next iteration.
>
> > I'm calling stopManagingCursor to avoid the crash described at <http://
> > groups.google.com/group/android-developers/browse_thread/thread/
> > f6fabc180e8b517a/c04691d80f1e9135?lnk=gst&#c04691d80f1e9135> (and a
> > few other posts you can find by searching this group for
> > "SQLiteClosable").
>
> > I suspect this is a bug in Activity.performStop, which shouldn't
> > assume mManagedCursors is constant through a call to a user-provided
> > callback. Until the Android developers can fix the bug, I'm looking
> > for a workaround. Should I just abandon managed cursors, which don't
> > seem to work well with CursorAdapters? Is there a good way to prevent
> > my OnItemSelectedListener from being called during performStop()? Any
> > other ideas?
>
> > Thanks,
> > Jeffrey
--~--~---------~--~----~------------~-------~--~----~
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