LittleFunny
LittleFunny

Reputation: 8385

Android: Managing cursor passing to CursorAdapter

On Ice cream sandwich, my application starts force close when I wanted to resume the application that has a gridview with a CursorAdapter that have passed in a managedQuery to a CursorAdapter. The Exception would be StaleDataException that saying I am attempting to access cursor which is being closed.

I used the getContextResolver().query instead of using managedQuery. The help me stop having force closed of the applicatio when i tried to resume the application.

In that case, if I used this way. Do I need to close the cursor or will it be closed by Adapter.

Upvotes: 1

Views: 3627

Answers (1)

sandrstar
sandrstar

Reputation: 12643

As per Activity documentation using managedQuery You don't need to close the cursor manually, but using ContentResolver manually You will need to do so. Adapter won't close the cursor, because it doesn't know (instead of Activity) when user left application and cursor is no longer needed. Usually it might be enough to call changeCursor() with null (adapter will close old one) or swapCursor() with null (and close returned cursor manually).

But I would suggest to take a look at CursorLoader as more handy, reliable and suggested by Google way to load cursors. Consider using support library v4 if You're targeting old Android.

Upvotes: 1

Related Questions