1

I recently wrote a StackOverflow Documentation example, illustrating how to populate a ListView from a database using a SimpleCursorAdapter.

It got rejected by with the following motivation:

Nobody should be using CursorAdapters anymore. They were deprecated for a reason!

I was unaware that cursor adapters were deprecated (and for what reason), so I Googled it. All that turned up were a bunch of posts asking roughly the same question I am asking right now, and the standard answer seemed to be "Only one of the constructors are deprecated, not the entire CursorAdapter class!"

So which way is it? Was my contribution rightfully rejected or not?

How should a ListView be populated, if not by a SimpleCursorAdapter? I know there are things like CursorLoader, but for a simple task like displaying some data in a ListView it seems like an unnecessary hassle to have to deal with content providers and stuff, when the same thing can be accomplished with an AsyncTask and a SimpleCursorAdapter...

Magnus
  • 17,157
  • 19
  • 104
  • 189
  • AFAIK, they're not deprecated, but I'd like to know why that user believes they are. That is, do they have an official source for that info? Maybe I'm just out of the loop. – Mike M. Aug 06 '16 at 00:10
  • Yeah I'd like to know the same, but I couldn't find any way to contact the user who rejected my example and ask them... – Magnus Aug 06 '16 at 10:12
  • You could open a [chat room with him](http://chat.stackoverflow.com/users/4409409/), and see if he responds. That's a toss-up, though. Some users don't like chat. He's pretty active on-site, so odds are decent that he'll be around sometime soon to see the room invite. – Mike M. Aug 06 '16 at 10:29

1 Answers1

1

Only the constructor which by default uses FLAG_AUTO_REQUERY is deprecated because:

This constant was deprecated in API level 11. 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.

Still you can do something like this:

CursorAdapter myAdapter = new CursorAdapter(myContext, myCursor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) {
    ...
dreinoso
  • 1,479
  • 17
  • 26