如何(正确)从startManagingCursor转换到CursorLoader?

时间:2012-04-13 17:47:12

标签: android cursor android-cursorloader

我将我的Android SDK更新为最新版本,现在它说startManagingCursor()deprecated。我需要帮助才能更新我的代码以使用新的CursorLoader

private void fillData() {
    Cursor notesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(notesCursor);
    NoteAdapter notes = new NoteAdapter(this,  R.layout.notes_row, notesCursor);
    setListAdapter(notes);
}

所以,startManagingCursor()已经过时了,新代码会是什么样的,如果它被翻译了?

1 个答案:

答案 0 :(得分:16)

首先,startManagingCursor()仍然有效。它并不理想,因为它在主应用程序线程上执行数据库I / O.在Android中,“弃用”通常意味着“我们还有其他一些我们认为更好的建议您使用”。因此,当您在应用的开发周期中有意义时,您应该考虑迁移。

其次,正如Selvin所说,SDK仅为Loader提供了ContentProvider实现。我直接a project that offers a Loader for SQLite

第三,你的代码确实没有直接的“翻译”。 Loader框架是异步的,事件驱动的,而你的代码不是。

一般来说,Loader负责提取笔记,当ListView从{onLoadFinished()发送时,您会在Cursor填充Loader {1}}。