Search code examples
androidandroid-cursorloader

When to use cursor loaders?


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.


Solution

  • 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);