2012-01-09 40 views
30

SimpleCursorAdapter不赞成它的构造与下面的注释之一:API版本15中不推荐使用SimpleCursorAdapter?

已过时。不鼓励使用此选项,因为它会导致在应用程序的UI线程上执行游标查询,因此可能导致响应性较差甚至出现应用程序无响应错误。作为替代方法,使用带有android.content.CursorLoader的android.app.LoaderManager。

这是否使整个类不推荐?另一个(标准)构造函数不被弃用。

+0

您是否有一个如何在LoadManager和CursorLoader中使用适配器的示例? – DevZer0 2013-08-11 07:35:43

回答

49

只有构造函数被弃用,而不是整个类。

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线程 正在执行[...]

所以也构造已被弃用。

不推荐使用标准构造函数,但很明显,您不必使用flags = FLAG_AUTO_REQUERY来调用它!

最后,如果你正在使用SimpleCursorAdapterCursorLoader,如文档建议, 不需要这个标志,你可以通过0

+1

以下是文档:https://developer.android.com/training/load-data-background/setup-loader.html – 2015-09-03 09:21:24

相关问题