startManagingCursor过渡到CursorLoad

startManagingCursor过渡到CursorLoad

本文介绍了如何(正确)从startManagingCursor过渡到CursorLoader?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了我的android SDK 到最新版本,现在它说, startManagingCursor() pcated德$ P $ 。我需要帮助来更新我的code使用新的 CursorLoader

I updated my android SDK to the latest version, and now it says that startManagingCursor() is deprecated. I need help to update my code to use the new CursorLoader.

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

因此​​, startManagingCursor()老了,会有什么新的code样子,如果它被翻译?

So, startManagingCursor() is old, what would the new code look like, if it was translated?

推荐答案

首先, startManagingCursor()仍然有效。这是不理想的,因为它执行数据库I / O主应用程序线程上。在Android中,德precated通常是指我们有我们认为是更好的,我们建议你用别的东西。所以,当它是有道理的在应用程序的开发周期,你应该考虑迁移。

First, startManagingCursor() still works. It is not ideal, in that it performs database I/O on the main application thread. In Android, "deprecated" generally means "we have something else that we think is better that we suggest you use". So, when it makes sense in the development cycle of your app, you should consider migrating.

其次,Selvin指出,该SDK只提供了一个装载机实施了的ContentProvider 。我有一个项目,提供了一个装载机 SQLite的直接。

Second, as Selvin noted, the SDK only provides a Loader implementation for a ContentProvider. I have a project that offers a Loader for SQLite directly.

三,实在是没有直线上升的翻译为你code。该装载机框架是异步的,事件驱动的,而你的code不是。

Third, there really is no straight-up "translation" for your code. The Loader framework is asynchronous and event-driven, whereas your code is not.

一般来说,你的装载机将负责获取笔记,你会填充的ListView onLoadFinished(),当你交付的光标装载机

Generally speaking, your Loader would be responsible for fetching the notes, and you would populate your ListView in onLoadFinished(), when you are delivered the Cursor from the Loader.

这篇关于如何(正确)从startManagingCursor过渡到CursorLoader?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 11:20