0

When I use SQLite to bring my data and use cursor and adapters, should I use cursor Loaders??. Is this the best practice?. Im not quite clear when to use cursor loaders. Should I use it only if my app shares data with other apps?. My question comes because it have been really annoying for me using cursors + adapters + listView; sometimes the notifyDataSetChanged works, sometimes not, so it have been really tricky sometimes. I start reading about cursor loaders but Im not sure if this is a work around for this in particular or if I can use it as a work around.

Any clarification will be really appreciated!!

Thanks guys.

kiduxa
  • 3,339
  • 11
  • 37
  • 52

1 Answers1

1

Use Loaders to ensure that all cursor operations are done asynchronously, thus eliminating the possibility of blocking the UI thread.

When using CursorAdapter don´t use notifyDataSetChanged instead use:

db.updateData();
yourCursor = db.getData();  
yourAdapter.changeCursor(yourCursor);
ramaral
  • 6,149
  • 4
  • 34
  • 57
  • so, should I use cursors loaders? even when my app wont share its database with other apps? – kiduxa Oct 29 '13 at 15:03
  • Cursor loaders don't enable database share. If you want share database with other apps use ContentProvider see [this](https://thenewcircle.com/s/post/1375/android_content_provider_tutorial). Cursor loaders are introduced with Android 3.0 to facilitate cursor operations asynchronously. If you only read small chunks of data is ok not use cursor loaders. Read [this](http://www.androiddesignpatterns.com/2012/07/loaders-and-loadermanager-background.html) to more on cursor loaders – ramaral Oct 29 '13 at 15:28
  • I mentioned the database sharing because cursor loaders uses contentProviders and contentPorviders as you said are used to share data between apps. Thats why Im confuse, but no I dont need to share database. So, should I use cursor loaders only if a have a large database? – kiduxa Oct 29 '13 at 16:00
  • Can I use cursor loaders without using contentProviders? – kiduxa Oct 29 '13 at 16:01
  • No. But you can do some similar see [this](http://stackoverflow.com/a/7422343/2556111) – ramaral Oct 29 '13 at 16:17
  • Thanks a lot ramaral, your posts have been really helpful! :). – kiduxa Oct 29 '13 at 16:27