开发者

Problem with "Finalizing Cursor" error in custom CursorAdapter

I have a cursor adapter and the logcat is filled with above errors, as soon as I click on a view. I am already relea开发者_开发百科sing the CursorAdapter's cursor in onDestroy().

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


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.


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


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.


Use the startManagingCursor(c) is not useful,maybe cause others bug, like trying to requery an already cloesd cursor,you can use c.close(), releasing the CursorAdapter's cursor in onPause(). not in the onDestroy(). ps: this maybe userful in android4.0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜