Android eclipse startManagingCursor 已弃用但希望支持旧 API 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9771582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android eclipse startManagingCursor Deprecated but want to support older API versions?
提问by Nick
I am trying to understand something, and I am sure it is very basic to some people.
我试图理解一些东西,我相信这对某些人来说是非常基本的。
I read everywhere that the startManagingCursor method is deprecated and you should use the CursorLoader class. But does that mean that you should use the CursorLoader class even for apps that support API levels < 11? Or is it saying that if you intend to only support Honeycomb and up, THEN use cursorLoader?
我到处都读到 startManagingCursor 方法已被弃用,您应该使用 CursorLoader 类。但这是否意味着即使对于支持 API 级别 < 11 的应用程序,您也应该使用 CursorLoader 类?还是说如果你打算只支持 Honeycomb 及以上,那么使用 cursorLoader?
I don't appear to be able to import the cursor loader class with api 4, so i assume that using CursorLoader doesn't apply until Android 3.0+, but can someone verify for me please?
我似乎无法使用 api 4 导入游标加载器类,所以我假设使用 CursorLoader 直到 Android 3.0+ 才适用,但有人可以帮我验证吗?
Thanks
谢谢
回答by CommonsWare
I read everywhere that the startManagingCursor method is deprecated and you should use the CursorLoader class.
我到处都读到 startManagingCursor 方法已被弃用,您应该使用 CursorLoader 类。
If you are willing to inherit from FragmentActivity
, you can use the Loader
framework implementation in the Android Support package, going all the way back to Android 1.6.
如果您愿意继承自FragmentActivity
,您可以使用Loader
Android 支持包中的框架实现,一直追溯到 Android 1.6。
That being said, "deprecated" in Android usually means "we will continue to support this, but we think there are better solutions". You can certainly use startManagingCursor()
on API Level 11+. However, the problems with managed cursors (notably that they requery()
on an activity restart on the main application thread) are still there, on older and newer Android versions.
话虽如此,Android 中的“弃用”通常意味着“我们将继续支持这一点,但我们认为有更好的解决方案”。您当然可以startManagingCursor()
在 API 级别 11+ 上使用。但是,托管游标的问题(特别是它们requery()
在主应用程序线程上重新启动活动时)仍然存在,无论是旧版还是新版 Android 版本。
But does that mean that you should use the CursorLoader class even for apps that support API levels < 11?
但这是否意味着即使对于支持 API 级别 < 11 的应用程序,您也应该使用 CursorLoader 类?
You certainly can, and, all else being equal, you probably should. However, all else is rarely equal, and the FragmentActivity
requirement may be a problem for you.
您当然可以,而且在其他条件相同的情况下,您可能应该这样做。然而,所有其他的东西很少是平等的,这个FragmentActivity
要求对你来说可能是个问题。
If you are developing a new application, today, you should be thinking about fragments from the outset, in which case you would be using FragmentActivity
anyway, and therefore using Loader
should not be a problem.
如果你正在开发一个新的应用程序,今天你应该从一开始就考虑片段,在这种情况下你FragmentActivity
无论如何都会使用,因此使用Loader
应该不是问题。
I don't appear to be able to import the cursor loader class with api 4
我似乎无法使用 api 4 导入游标加载器类
The Android Support package implementation of Loader
works on API Level 4 and above.
Loader
适用于 API 级别 4 及更高级别的 Android 支持包实现。