Why is Cursor.requery() marked “deprecated”?

最后都变了- 提交于 2019-12-13 14:29:01

问题


Cursor.requery() is a very common method while using it to refresh a ListView's content. But why is this method marked "deprecated"? I can't understand the reason on the API docs very clearly.

Cursor.requery() API: http://developer.android.com/reference/android/database/Cursor.html#requery()

Can anyone please explain the reason any further? Thanks:)


回答1:


I believe it was done because new Loaders API was introduced to simplify querying Cursors asynchronously.

As deprecation note says

Don't use this. Just request a new cursor, so you can do this asynchronously and update your list view once the new cursor comes back.

that's what we should be using.

update

It seems that it can also be related to deprecation of Activity.startManaginCursor:

startManagingCursor(Cursor c) This method is deprecated. Use the new CursorLoader class with LoaderManager instead; this is also available on older platforms through the Android compatibility package. This method allows the activity to take care of managing the given Cursor's lifecycle for you based on the activity's lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is later restarted it will call requery() for you. When the activity is destroyed, all managed Cursors will be closed automatically. If you are targeting HONEYCOMB or later, consider instead using LoaderManager instead, available via getLoaderManager()



来源:https://stackoverflow.com/questions/7073341/why-is-cursor-requery-marked-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!