Search code examples
androidandroid-activityandroid-cursor

Closing Cursor Android


I'm creating an app and in an activity i have a listview with several items. when i click in an item, i start a new activity with the id of the item clicked. after the click, i close the db and the cursor in onStop. i do it in onStop because if i close the in onPause the user can see the listview becoming empty before the new activity starts. it actualy works pretty well, the problem is that i'm testing when the user presses the on/off button that suspends the device. if this happens i get the error that the cursor wasn't close. to close the cursor right. i would have to close the cursor in onPause, but if i close the cursor in onPause, the user see's the listview becoming empty.

What should i do?


Solution

  • So you are populating the data to list view

    How is it that your list goes empty, are you clearing the data in your list?

    You should close the db connection once you are done with your query/update/... action thats because there's not abundant connections available

    Android is designed to close the db connections automatically once the application is exited, but when there's scarce of connection this is the problem

    Once again verify why your list goes empty