1

I have found two different methods for implementing AsyncQueryHandler:

  1. One on the stackOverFlow
  2. Second on this blog.

In the first method we are not subclassing from AsyncQueryHandler while in the second method we are manualy closing the cursor.

I want to know that

Does AsyncQueryHandler not handle cursor? or we must close it manually (as done in the second method)?

Community
  • 1
  • 1
Shajeel Afzal
  • 5,913
  • 6
  • 43
  • 70

1 Answers1

0

AsyncQueryHandler, as seen in the source, does not handle any returned Cursor that is returned in onQueryComplete. Note that any of the other ContentProvider methods (insert, update, delete) do not return a Cursor and are therefore much easier to understand.

Generally, if you are going to query a ContentProvider and use the resulting data (to say, fill a ListView), you would want to use Loaders along with a CursorLoader. These classes are available in the support library and provide a much more robust framework (including automatically reloading data if the underlying ContentProvider data changes) for managing queries.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • The problem with `CursorLoader`s is that they are only made for loading `Cursor` from the DB using `ContentProvider`, I want to preform `Insert/Delete/Update` using `AsyncQueryHandler`. I dont want to use `AsyncTask` because `AsyncQueryHandler` is made specially for Asynchronous DB operations using ContentProviders. – Shajeel Afzal Apr 27 '13 at 06:50
  • @ShajeelAfzal - so what's your question? For Insert/Update/Delete `AsyncQueryHandler` is perfect and what is recommended for simple operations and there's no `Cursor` to close/not close in those cases. – ianhanniballake Apr 27 '13 at 14:09