Search code examples
androidandroid-4.0-ice-cream-sandwichsimplecursoradapterandroid-loadermanager

SimpleCursorAdapter in ICS


I need a SimpleCursorAdapter in my project. I've written code for this in 2.3 version. But i could not add this in ICS. It shows SimpleCursorAdapter(context, layout, c, from, to) is deprecated and the new one is SimpleCursorAdapter(context, layout, c, from, to, flags).

A new parameter "flags" is included in this. What should I add in the place of flags? What does this indicate?


Solution

  • To quote the Android reference, the flag parameter is of the following:

    public static final int **FLAG_AUTO_REQUERY**
    

    Since: API Level 11

    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.

    If set the adapter will call requery() on the cursor whenever a content change notification is delivered. Implies

     FLAG_REGISTER_CONTENT_OBSERVER. Constant Value: 1 (0x00000001)
    

    .

    public static final int **FLAG_REGISTER_CONTENT_OBSERVER** 
    

    Since: API Level 11

    If set the adapter will register a content observer on the cursor and will call onContentChanged() when a notification comes in. Be careful when using this flag: you will need to unset the current Cursor from the adapter to avoid leaks due to its registered observers. This flag is not needed when using a CursorAdapter with a CursorLoader. Constant Value: 2 (0x00000002)

    However, the new pattern for Honeycomb+ is to use a cursorLoader to manage the cursor for you. In this case, you pass 0 as the flags parameter.

    Read more (with tutorials) on CursorLoader + CursorAdapter