Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

android - SimpleCursorAdapter deprecated in API version 15?

SimpleCursorAdapter deprecates one of its constructors with the following comment:

Deprecated. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use android.app.LoaderManager with a android.content.CursorLoader.

Does this make the whole class deprecated? The other (standard) constructor is not deprecated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Only the constructor is deprecated, not the whole class.

SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to) calls SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to, int flags) with flags set to FLAG_AUTO_REQUERY.

But FLAG_AUTO_REQUERY is deprecated because

[...] it results in Cursor queries being performed on the application's UI thread [...]

so also the constructor is deprecated.

The standard constructor is not deprecated but, obviously, you don't have to call it with flags = FLAG_AUTO_REQUERY!

Finally, if you are using SimpleCursorAdapter with a CursorLoader, as the documentation suggests, this flag is not needed and you can pass 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...