I didn't catch previously that the exception started on in
performResume. I'm actually not certain whether the source of the
issue would be with Activity1 or Activity2, because in performResume I
believe the system dealing with switching Activities.
I haven't tried it, but a single cursor instance should be able to
have close() called on it more than once. Try not calling close() on
the managed Cursor, or if you *do* call close() yourself, also call
stopManagingCursor(). My speculation here is, let's say you have
Cursor 'c' in Activity1. You then do this sequence,
Activity1.startManagingCursor(c)->c.query()->c.close()-
>c.startActivity(Activity2)->Activity2.finish(). finish() is called
when the user presses the back button. Now, when Activity1 resumes, it
think it still needs to manage 'c' and will attempt to restore the
data to 'c' by running its query again. close() invalidates the
Cursor, so this will result in an error. This is utter speculation,
haven't tried it. I'll try to get some time to do it, but give it a
shot and see what your results are.
I don't think you should need to release ContentProviders.
Can you post your code for Activity1 and Activity2 in this instance?
Thanks,
Justin
Android Team @ Google
On Aug 20, 1:36 am, simon <[EMAIL PROTECTED]> wrote:
> Thanks for your help. But i still don't understand exactly what i'm
> doing wrong.
>
> I'm navigating from Activity1 to Activity2. Then i navigate back to
> Activity1 by pushing the Back-Button. You say i should overwrite
> onPause() on Activity2 to release its resources. So the error has
> nothing to do with Activity1? But i'm already using a managed Cursor
> plus i'm calling Cursor.close() in onPause() (just to be sure) in
> Activity2. Other Cursors i am using in other classes also get released
> (by calling close()) immediately after gathering information from
> them. so i don't know what i am doing wrong...is close() the wrong
> function to call?
>
> Do i have to release other resources as well? such as
> ContentProviders? i found out that ContentResolver got a new method
> called releaseProvider(IContentProvider icp). But it's not documented
> yet. should it be used to release the ContentProviders?
>
> just because i'm interested:
> why does the system try to acquire a reference on a Cursor if an
> activity gets closed anyway? i'm getting the following
> RuntimeException (which gets caused by the Exception i posted
> earlier):
>
> java.lang.RuntimeException: Unable to resume activity {my.package/
> my.package.Activity2}: java.lang.IllegalStateException: attempt to
> acquire a reference on a closeSQLiteClosable
>
> Why does the system tell me that it's unable to resume an Activity
> which i just wanted to close by pushing the back button? and what is a
> "closeSQLiteClosable"? shouldn't it read "closeDSQLiteClosable?" And
> if i release Cursors by calling close(), aren't these also "close
> SQLiteClosables" which can't be acquired? i just dont get it...
>
> I would be happy to get more information about what the system is
> doing between the Activities and why those strange error messages
> occur
>
> Thanks a lot
> Simon
>
> On Aug 19, 6:05 pm, "Justin (Google Employee)" <[EMAIL PROTECTED]>
> wrote:
>
> > My guess would be that you have an SQLite cursor that you're not
> > releasing when your Activity loses focus. I believe you have two
> > options.
>
> > You say that you've tried to handle this in callback functions
> > onRestart, onResume, etc. The problem is you're looking at the wrong
> > end of the lifecycle. When the user hits the 'back' key, onPause is
> > called. In onPause you should handling releasing resources and any
> > other tear-down you need to do. I'd suggest reviewing the Activity
> > lifecycle information
> > (http://code.google.com/android/reference/android/app/Activity.html
> > ) .
>
> > The other option is to use a managed cursor. To do this call
> > Activity.startManagingCursor(yourCursor).
>
> > Cheers,
> > Justin
> > Android Team @ Google
>
> > On Aug 19, 7:16 am, simon <[EMAIL PROTECTED]> wrote:
>
> > > Hi all!
> > > First of all i wanted to say thank you to Google for the new SDK!
> > > Lookin forward to the phones!
>
> > > now to my problem:
> > > as soon as i push the back button in some of my application's
> > > activities, i get the following error:
>
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): Caused by:
> > > java.lang.IllegalStateException: attempt to acquire a reference on a
> > > closeSQLiteClosable
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:
> > > 31)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:109)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:129)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:389)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.database.CursorWrapper.requery(CursorWrapper.java:214)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.app.Activity.performRestart(Activity.java:3330)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.app.Activity.performResume(Activity.java:3350)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): at
> > > android.app.ActivityThread.performResumeActivity(ActivityThread.java:
> > > 2482)
> > > 08-19 14:10:13.050: ERROR/AndroidRuntime(1183): ... 10 more
>
> > > What does that mean? and is there a workaround? i already tried
> > > different callback functions (onRestart(), onResume(),
> > > onRestoreInstanceState()) but none gets called before the error
> > > occurs. how can i do something before that error occurs? and what
> > > should i do against it once i get a callback? i don't understand the
> > > error message. it worked on m5, but 0.9 just won't do it.
>
> > > please help me. Thanx a lot!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---