Android数据库Cursor操作:I… 分类: Android数据存储 2014-05-30 10:58 70人阅读 评论(0) 收藏

问题描述:
在开发Android数据库应用程序的时候,出现错误,打开logcat程序发现错误信息如下:
Cursor | Invalid statement in fillWindow()

问题分析:
出现这种问题的主要原因是因为你的数据库在Cursor关闭之前就关闭了,导致Cursor.requery()操作失败。
因为使用了startManagingCursor()函数, 按照api中描述:
This method allows the activity to take care of managing the given Cursor's lifecycle for you based on the activity's lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is later restarted it will call requery() for you. When the activity is destroyed, all managed Cursors will be closed automatically.
可以看到, cursor声明周期将与Activity共同管理, 而当你返回List页时, 系统自动requery() 时, 我的DB连接已经关闭, 因为, 我在onStop方法中close()的.

解决办法:
在onDestroy中进行db close. 而且, 在从子Activity返回此parentActivity时, 也不需要renderListView(), 因为Android自动为我们从新requery啦
posted @ 2014-05-30 10:58  leansmall  阅读(101)  评论(0编辑  收藏  举报