【android】使用CursorAdapter注意事项
2012-09-04 10:04
477 查看
项目中用到了CursorAdapter,总结如下:
有时候会报这样的错误。比如在tab中有一个activity使用了CursorAdapter,点击tab,停顿会出现这样的异常:java.lang.IllegalStateException: trying to requery an already closed cursor
经过分析。由activity在通过query获取了Cursor之后用startManagingCursor来管理Cursor的生命周期就不会出现这样的异常;
但是在之后的测试中发现,在Build.VERSION.SDK_INT ==11或者以上的版本还会出现这样的错误。只好在Build.VERSION.SDK_INT >=11的版本不管理游标,测试没有问题。
处理如下:
@Override
public void startManagingCursor(Cursor c) {
// To solve the following error for honeycomb:
// java.lang.RuntimeException: Unable to resume activity
// java.lang.IllegalStateException: trying to requery an already closed
// cursor
if (Build.VERSION.SDK_INT < ***Static.VERSON_C) {
super.startManagingCursor(c);
}
}
有时候会报这样的错误。比如在tab中有一个activity使用了CursorAdapter,点击tab,停顿会出现这样的异常:java.lang.IllegalStateException: trying to requery an already closed cursor
经过分析。由activity在通过query获取了Cursor之后用startManagingCursor来管理Cursor的生命周期就不会出现这样的异常;
但是在之后的测试中发现,在Build.VERSION.SDK_INT ==11或者以上的版本还会出现这样的错误。只好在Build.VERSION.SDK_INT >=11的版本不管理游标,测试没有问题。
处理如下:
@Override
public void startManagingCursor(Cursor c) {
// To solve the following error for honeycomb:
// java.lang.RuntimeException: Unable to resume activity
// java.lang.IllegalStateException: trying to requery an already closed
// cursor
if (Build.VERSION.SDK_INT < ***Static.VERSON_C) {
super.startManagingCursor(c);
}
}
相关文章推荐
- Android数据库使用cursor的注意事项!
- Android中CursorLoader的使用、原理及注意事项
- Android中CursorLoader的使用、原理及注意事项
- Android SQLiteOpenHelper onUpgrade使用注意事项
- android tinker 热修复使用及注意事项
- Android 强制横屏或竖屏注意事项及onConfigurationChanged的使用
- LocationManager Android自动定位使用以及注意事项(个人)
- Android 4.4 中 WebView 使用注意事项
- Android之线程安全的单例模式,Adapter注意事项之引用传值
- Android 4.4 中 WebView 使用注意事项
- Android中statfs使用注意事项
- 使用cocos2dx编译到Android注意事项和NDK-build参数设置
- 关于android:layout_weight属性使用注意事项
- Android使用 startActivityForResult 、 onActivityResult 时的注意事项
- Android使用Parcelable传递对象方法及注意事项
- Android开发之CardView使用的相关注意事项
- android SimpleCursorAdapter的使用
- Android开源库EventBus的使用及注意事项
- Android菜单设计(2) : options menu使用注意事项
- Android ActionBar 使用注意事项