On my app i am receiving reports of sporadic cursor errors that only come up on Motorola phones. I am using a ListView backed by a SQLite query to view a directory, and the query is refreshed when the directory is updated remotely or locally.
The most frequent errors we see are:
- java.lang.IllegalStateException: this should only be called when the cursor is valid
- java.lang.IllegalStateException: Cursor is closed
- android.database.StaleDataException: Access closed cursor
- java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.CursorWindow
Is this a known problem, and is there a fix or a workaround?
I use AsyncTask to update the list:
private class RefreshTask extends AsyncTask<Void, Void, Cursor> {
protected Cursor doInBackground(Void... params) {
return ReaderHelper.getItemCursor(getActivity(), ReaderHelper.itemFilter);
}
protected void onPostExecute(Cursor csr) {
int count = csr.getCount();
loadingBar.setVisibility(View.GONE);
if (count == 0) {
if (ReaderHelper.itemFilter.unread) emptyMessage.setText(getText(R.string.msg_no_item_unread));
else emptyMessage.setText(getText(R.string.msg_no_item));
}
mCursor = csr;
getActivity().startManagingCursor(mCursor);
mAdapter.changeCursor(mCursor);
}
}
This is the adapter.
private class ItemsAdapter extends ResourceCursorAdapter {
private ItemsAdapter(Context c, Cursor csr) {
super(c, R.layout.item_list_row, csr, false);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = super.newView(context, cursor, parent);
view.setTag(new ItemViewHolder());
return view;
}
@Override
public void bindView(View v, Context c, Cursor csr) {
...
}
}