Thanks for the quick response!  That's what I also thought, but then I
get these exceptions.  I glanced at the Android sources, and here is
what I *think* is going on if I use managed cursors:

- Cursor returned by FilterQueryProvider#runQuery() is passed on to
SimpleQueryAdapter#changeCursor()
- changeCursor() calls close() on the *previous* cursor (which is also
managed)
- However, this is not reflected in any way in
Activity#mManagedCursors (mReleased is still false)
- If the activity is paused, then Activity#performStop() deactivates
all managed cursors and sets them to be requeried on resume
- When the activity resumes, Activity#performRestart() tries to
requery those closed cursors and the application dies

As far as I can tell, there is no hook in FilterQueryProvider (or
elsewhere), where I can call Activity#stopManagingCursor() on the old
cursor to avoid this.  Also, it seems there is no way to iterate over
the managed cursors in onPause() to perform a post-mortem cleanup (no
accessor for Activity#mManagedCursors).

Or am I missing something?

Thanks,
Spiros

On Feb 10, 7:17 pm, Romain Guy <romain...@google.com> wrote:
> It's up to you. If you don't use managed cursors, you will have to
> close/query them yourself when the activity is
> destroyed/created/stopped, etc.
>
>
>
> On Tue, Feb 10, 2009 at 4:14 PM, Spiros <spapa...@gmail.com> wrote:
>
> > Hi,
>
> > I'm using an autocomplete box, with suggestions provided by a
> > SimpleQueryAdapter, almost identical to the code in this thread:
> >    http://groups.google.com/group/android-developers/browse_thread/threa...
> > Not sure if relevant, but only difference I see is that, both in the
> > adapter constructor, as well as in runQuery(), I use a cursor returned
> > by SQLiteDatabase#query() obtained via an SQLiteOpenHelper instance.
>
> > Should I be using Activity#startManagingCursor() on these cursors or
> > not?
>
> > If I don't use managed cursors, then I get "leak found" warnings
> > ("database was created [sic] but never closed").
>
> > If I do then, if the application pauses (e.g., incoming call) and then
> > resumes, I get an unhandled exception ("attempted to requery closed
> > cursor" thrown by Activity#performRestart(), in Activity.java:3333 --
> > SDK 1.0_r2, btw).
>
> > What am I missing?
>
> > Thanks!
> > Spiros
>
> --
> Romain Guy
> Android framework engineer
> romain...@android.com
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support.  All such questions should be posted on
> public forums, where I and others can see and answer them
--~--~---------~--~----~------------~-------~--~----~
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