Question

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?

Was it helpful?

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

OTHER TIPS

I've figured it out. The problem was that i was closing the cursor in onStop and i was recreating it in onResume when it should be created in onStart. My advice is that the cursor's and dbs should be open/closed in onStart/onStop

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top