Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how do you code now if requery is deprecated?

As per the title, if we used to call cursor.requery(), but it is now deprecated. How do you call this function now?

This method is deprecated. Don't use this. Just request a new cursor, so you can do this asynchronously and update your list view once the new cursor comes back.

So how does one request a new cursor and pass it back to the adapter?

like image 506
Maurice Avatar asked Aug 23 '11 06:08

Maurice


3 Answers

Re-initialize cursor when your any DML query execute.

See also this.

like image 61
Mohammed Azharuddin Shaikh Avatar answered Sep 23 '22 20:09

Mohammed Azharuddin Shaikh


Just think about a block where you need to use cursor again and again. Populate it with the query. Work with it and then close before reusing

{
    Cursor c =//Populating cursor again
    while (c.moveToNext()) {
    }
    if (c != null) c.close();
}
like image 20
Rasel Avatar answered Sep 24 '22 20:09

Rasel


Use a Loader to manage your cursors. It will return a new Cursor as needed and you can use swapCursor() on the adapter to refresh the data.

like image 43
Nikolay Elenkov Avatar answered Sep 21 '22 20:09

Nikolay Elenkov