【android】使用CursorAdapter注意事项
16lz
2021-01-26
项目中用到了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);
}
}
更多相关文章
- java.lang.RuntimeException: Unable to instantiate activity C
- SwipeRecyclerview使用中一些常见错误处理方法【持续更新中】
- Android(安卓)不依赖于Activity的全局对话框Dialog
- [原]android 链接错误
- 如何解决向eclipse导入android project时遇到错误“Invalid proj
- 自己编译的android sdk无法识别各版本platform的问题
- 解决-Android: 跨应用AIDL调用时报错 java.lang.SecurityExcepti
- ubuntu编译ffmpeg的动态库的一些坑
- gradle统一管理版本号