SimpleCursorAdapter在API版本15中被弃用了吗?

30

SimpleCursorAdapter已经废弃了其中一个构造函数,附带以下注释:

已弃用。不建议使用此选项,因为它会在应用程序的UI线程上执行Cursor查询,从而可能导致响应性差或甚至出现“应用程序未响应”错误。作为替代方案,请使用android.app.LoaderManager和android.content.CursorLoader。

这是否使整个类都被废弃了?另一个(标准)构造函数没有被弃用。


你有使用适配器与LoadManager和CursorLoader的示例吗? - DevZer0
1个回答

53

只有构造函数被弃用了,而非整个类。

SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to) 调用 SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to, int flags),其中的flags被设置为FLAG_AUTO_REQUERY

但是FLAG_AUTO_REQUERY被弃用了,因为它会导致在应用程序的UI线程上执行Cursor查询,所以构造函数也被弃用了。

标准构造函数并没有被弃用,但显然你不必使用flags=FLAG_AUTO_REQUERY来调用它!

最后,如果您正在使用文档建议的SimpleCursorAdapterCursorLoader,则不需要此标志,您可以传递0


1
这里是文档:https://developer.android.com/training/load-data-background/setup-loader.html - ban-geoengineering

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接