我刚刚开始使用新的 cursorLoader 并且遇到了问题。以下代码只是为了了解 cursorLoader 的工作原理,但我不断得到:
“尝试重新查询已关闭的游标”,当我恢复此活动时。在我开始使用 cursorLoader 之前,该应用程序运行良好。有任何想法吗?
private Cursor getSectionData(CharSequence parent_id) {
String[] projection = new String[] {Titles.SECTION, Titles.TITLE, Titles._ID, Titles.CODE_RANGE,};
Uri titles = Titles.CONTENT_URI;
String select = "" + Titles.PARENT_ID + " match " + parent_id + "";
CursorLoader loader = new CursorLoader(this, titles, projection, select, null, null);
Cursor cTitles = loader.loadInBackground();
String[] projection1 = new String[] {Codes.CODE, Codes.EXCERPT, Codes._ID,};
Uri codes = Codes.CONTENT_URI;
String select1 = "" + Codes.PARENT_ID + " match " + parent_id + "";
CursorLoader loader1 = new CursorLoader(this, codes, projection1, select1, null, null);
Cursor cCodes = loader1.loadInBackground();
//Cursor cTitles = db.rawQuery("select section, title, _id, code_range from titles where parent_id match " + parent_id + "", null);
//startManagingCursor(cTitles);
//Cursor cCodes = db.rawQuery("select code, excerpt, _id from codes where parent_id match " + parent_id + "", null);
mQuery = "select code, excerpt, _id from codes where parent_id match " + parent_id + "";
//startManagingCursor(cCodes);
Cursor[] c = {cTitles, cCodes};
Cursor cursor = new MergeCursor(c);
startManagingCursor(cursor);
return cursor;
}