我将我的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()
已经过时了,新代码会是什么样的,如果它被翻译了?
答案 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}}。