A getContentResolver request raises a CursorWrapperInner warning

In version 4.0.3, the code below triggers the warning "W / CursorWrapperInner (11252): the cursor is completed without first closing ()".

Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); getContentResolver().query(uri, null, null, null, null); 

In sorce, I found a warning, where did he come from, will someone tell me how to avoid, since I doubt this is due to some strange problem?

enter image description here

+6
source share
2 answers

I also experienced this strange problem. I use ContentProvider to provide me with a cursor and CursorLoader to handle the selection in my fragment / actions. Therefore, I do everything "in the book."

I experienced this warning message using a 4.1.1 device, but it seems to have gone to my Nexus 7, which is 4.2. Personally, I would not seriously notice this warning.

Update: I tested my code with Android v2.2 and I got the full stack from this error. It turned out that my code was extracting another cursor (not the one that was selected using Loader), and that was the code violation. Closing it manually did the trick.

+2
source

This line of code returns a Cursor object:

 getContentResolver().query(uri, null, null, null, null); 

It is odd that you execute the request, but ignore the result. The sole purpose of executing the query is to get the results in the cursor. You should save this in a variable as follows:

 Cursor cursor = getContentResolver().query(uri, null, null, null, null); 

Then you can use the cursor to get any data you need, and when you are done with it:

 cursor.close(); 

You can close the cursor in Activity#onDestroy() or earlier, but you must close it before the operation is completed or you will see this warning. This is because the cursor is supported by memory in another process, and you do not want to leak this memory.

0
source

Source: https://habr.com/ru/post/923443/


All Articles