Android sqlite leaving connection open Android sqlite leaving connection open sqlite sqlite

Android sqlite leaving connection open


Open a connection as late as possible. Close it as soon as possible. Close it in a "finally" block to make sure it gets closed.

And in general, dispose of resources in the reverse order that you obtain them.


You are basically bloating your application by having an extra cursor open. Best practice is to close the connection.

I have noticed that there are a lot of exceptions thrown if you dont do it.


If you don't close the database connections, they'll cause memory leaks over time. you can use startManagingCursor but along with this you have to close the db connection. by the way what type of error or exception you are getting while closing db connection in onStop() or onDestroy() method