HTC Desire Dev Tipp – managedQuery
Many of you are probably developing for Android. Some commercially some just for fun. However, I recently came across a little, but important mistake some tutorials inherit when it’s about Content Providers using SQLite. There are several methods to query your database but one seems especially easy to use: it’s the managedQuery -Method. Although it is listed as deprecated it’s pretty popular. However, usually you have to use close(). This is not true for a Cursor which got returned by a managedQuery. It will cause a ANR (Application Not Responding) Error, which results in a crashed application. It is already named managedQuery, it manages its lifecycle on its own. All other Cursors need to be closed, e.g. in onDestroy().
Closing the managedQuery-Cursor will result in crashing the Application on Honeycomb (or later) devices.
I hope I could help!



