views:

57

answers:

3

I have a cursor adapter and the logcat is filled with above errors, as soon as I click on a view. I am already releasing the CursorAdapter's cursor in onDestroy().

Is there any way to get information about when the cursor was opened?

A: 

Use startManagingCursor(cursor) instead of the onDestroy() option - this is much cleaner and better.

Sameer Segal
A: 

You should use startManagingCursor(c) in your ListActivity right after you initialized your Cursor. Than the activity will handle the cursor and you don't have to care about it.

WarrenFaith
As far as I understand it I can use startManagingCursor only in a Activity context. Unfortunately I am using a CursorTreeAdapter and have to manage the Cursor in getChildCursor(Cursor groupCursor) by myself (as stated in the documentation).
Christian Kirsch
+1  A: 

I was looking for the same thing and poked around the SDK.

The cursor finalizer looks if some debug properties are set and prints out the whole stacktrace if requested. They can be found in SQLiteDebug.java in the Android sourcecode.

/**
 * Controls the stack trace reporting of active cursors being
 * finalized.
 */
 public static final boolean DEBUG_ACTIVE_CURSOR_FINALIZATION =
   Log.isLoggable("SQLiteCursorClosing", Log.VERBOSE);

Just set the property (with adb shell) log.tag.SQLiteCursorClosing and check logcat again.

setprop log.tag.SQLiteCursorClosing Log.VERBOSE

This might only work in Froyo and above, I did not check the source for the older SDKs.

ThomasD
wow - exactly what I was looking for. With the more verbose exception information I could fix my code. Thank you!
Christian Kirsch
interesting, thank you for sharing!
WarrenFaith