【问题标题】:SimpleCursorAdapter deprecated in API version 15?API 版本 15 中已弃用 SimpleCursorAdapter?
【发布时间】:2012-01-09 15:20:25
【问题描述】:

SimpleCursorAdapter 弃用了它的构造函数之一,并带有以下注释:

已弃用。不鼓励使用此选项,因为它会导致在应用程序的 UI 线程上执行游标查询,从而导致响应速度不佳甚至应用程序无响应错误。作为替代方案,将 android.app.LoaderManager 与 android.content.CursorLoader 一起使用。

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

【问题讨论】:

  • 你有一个例子说明如何将适配器与 LoadManager 和 CursorLoader 一起使用?

标签: android simplecursoradapter


【解决方案1】:

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

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

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
  • 1970-01-01
  • 2021-09-03
  • 1970-01-01
  • 2021-08-28
  • 2017-08-20
  • 2023-01-23
相关资源
最近更新 更多