項目中用到了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);
}
}