2012-01-09 64 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