Pretty simple.
What is the difference among those three?
I want to list every Image in a device.
Should I use managedQuery(), android.provider.MediaStore.Images.Media.query() or context.getContentResolver.query()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
managedQuery()will use ContentResolver’s query(). The difference isthat with
managedQuery()the activity will keep a reference to yourCursor and close it whenever needed (in
onDestroy()for instance.) Ifyou do
query()yourself, you will have to manage the Cursor as asensitive resource. If you forget, for instance, to
close()it inonDestroy(), you will leak underlying resources (logcat will warn youabout it.)
To query a content provider, you can use either the
ContentResolver.query()method or theActivity.managedQuery()method. Both methods take the same set of arguments, and both return a Cursor object. However,managedQuery()causes the activity to manage the life cycle of the Cursor. A managed Cursor handles all of the niceties, such as unloading itself when the activity pauses, and requerying itself when the activity restarts. You can ask an Activity to begin managing an unmanaged Cursor object for you by callingActivity.startManagingCursor().Update:
managedQueryis now deprecated (as of Android 3.0).