If you're using a managed cursor you shouldn't be calling close() or
deactivate() on the cursor yourself, since the system will do that for
you. If you're not using a managed cursor and you call close() on it
you cannot use that cursor again and should make sure that you don't
have any observers registered before calling close(), and then
explicitly set all references you hold to the cursor to null just to
make sure you won't use it again. If you plan on reusing the cursor
again, you should call deactivate(), which releases a bunch of
resources, but not all of them. A deactivated cursor can't be used
again until you call requery() on it.
-Jeff
On Wed, Aug 20, 2008 at 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 close SQLiteClosable
>
> 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
> "close SQLiteClosable"? shouldn't it read "closeD SQLiteClosable?" 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
>> > close SQLiteClosable
>> > 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
-~----------~----~----~----~------~----~------~--~---