What CursorAdapter have I to use?
Asked Answered
S

3

9

CursorAdapter have 3 constructors. Let see the guide and reference.

1) CursorAdapter(Context context, Cursor c)

This constructor is 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 LoaderManager with a CursorLoader.

2) CursorAdapter(Context context, Cursor c, boolean autoRequery)

Constructor that allows control over auto-requery. It is recommended you not use this, but instead CursorAdapter(Context, Cursor, int).

3) CursorAdapter(Context context, Cursor c, int flags)

Recommended constructor.

flags Flags used to determine the behavior of the adapter; may be any combination of FLAG_AUTO_REQUERY and FLAG_REGISTER_CONTENT_OBSERVER.

FLAG_AUTO_REQUERY This constant is 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 LoaderManager with a CursorLoader.

FLAG_REGISTER_CONTENT_OBSERVER. This flag is not needed when using a CursorAdapter with a CursorLoader.

CursorAdapter(Context context, Cursor c, int flags) is the recommended constructor, but the possible flags are 2, one is deprecated and the other is not needed when using a CursorAdapter with a CursorLoader. If I use a CursorAdapter with a CursorLoader I have to use this constructor and pass zero as flag? And in this case is constructor the same than #1 deprecated?

Shere answered 20/11, 2011 at 22:10 Comment(0)
B
6

By using #1, it defaults the adapter to auto-requery. This differs from #3 because you can specify if you wish to auto-requery (which you shouldn't, per the documentation). So, no, #1 and #3 aren't the same if you pass the #3 constructor 0.

Banta answered 20/11, 2011 at 22:26 Comment(0)
S
1

CursorAdapter is an abstract class and as such can not be instantiated.

Also, keep in mind that the 3rd constructor is API 11+ only.

Spriggs answered 20/11, 2011 at 22:29 Comment(1)
Yes, my app has min version API 7 but I use compatibility packageShere
S
0

You need to migrate with LoaderManager and Loader.

because most probably all would be deprecated. so better to use CursorLoader with LoaderManager and Loader

You can find the sample project in the below link which gets the list of apps installed in any phone.

https://github.com/alexjlockwood/AppListLoader.git

Good luck..

Seaport answered 25/10, 2013 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.