API版本15中不推荐使用SimpleCursorAdapter吗?

时间:2012-01-09 15:20:26

标签: android simplecursoradapter

SimpleCursorAdapter 使用以下注释弃用其中一个构造函数:

已过时。不鼓励使用此选项,因为它会导致在应用程序的UI线程上执行Cursor查询,从而导致响应能力较差甚至应用程序无响应错误。作为替代方案,使用android.app.LoaderManager和android.content.CursorLoader。

这是否会使整个班级弃用?不推荐使用其他(标准)构造函数。

1 个答案:

答案 0 :(得分:52)

仅弃用构造函数,而不是整个类。

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