Finalizing a Cursor that has not been deactivated or closed non-fatal error

前端 未结 9 1489
慢半拍i
慢半拍i 2020-12-07 19:27

i\'m getting a \"Finalizing a Cursor that has not been deactivated or closed\" error on this piece of code. The code is used to fill a listview.

Since it\'s a non

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 19:44

    I too have been having issues with the closing the cursor:

    • Closing the cursor right after setting the list view's adapter causes the cursor to close before the data gets displayed.

    • Can't use startManagingCursor to manage the cursor because it has been deprecated.

    • The new cursorLoader replacement for startManagingCursor seems to be overkill.

    • Moving the cursor's position as suggested did not work.

    • Making the task an inner class of the activity and closing the cursor in the activity's onDestroy method works sometimes but not all the time.

    • Making the task an inner class of the activity and closing the cursor in the activity's onStop method seems to be working.

    I also found out that I can close the database and the sqlite open helper before closing the cursor. I can even close them right after setting the list view's adapter. The data will still display.

提交回复
热议问题