Reputation: 5403
What is weird about this is it doesn't happen every time. I am adding something to the database and if i do it a couples of times nothing happens, but if I keep adding and keep adding this error message occurs. Sometimes it happens the second time while other times it doesn't happen til the 5th. It seems to be random. Anyone have any idea why pressing the same combo of buttons wouldn't cause this error message every time?
Upvotes: 0
Views: 1635
Reputation: 407
You might be running into the same problem I had when getting data from a sqlite database for a ListView.
If you close the cursor after you are done with it... the ListView is blank.
If you do NOT close the cursor... the ListView will occasional generate that error you are seeing.
Solution? Make the cursor global to your class... and only close it once: When you are FULLY done with it. (Inside onDestroy and/or onStop).
I'm not sure why #1 happens. (I try to avoid using global vars. But can't avoid it here.)
Upvotes: 2
Reputation: 10471
First close the cursor in onDestroy and onStop like this:
if(mCursor!= null && !mCursor.isClosed())
mCursor.close();
and then try calling startManagingCursor(cursor)
after where you use your cursor object, if you use it to make a query, etc, call it after the operation you make with the cursor.
Upvotes: 2
Reputation: 115
You should be seeing the following before the error:
D/dalvikvm( 285): GC_FOR_MALLOC freed
It shows that the android machine is freeing potential leaks to get more memory. Your cursor is also a leak, since you are not closing it properly with <cursor>.close()
;
Upvotes: 1