Close or not close?

In recent days, I often got a lot of error messages due to a database leak in my application, so now I open the database, get query results from it and close the DB again.

But I also use cursoradapter for my autocomplete.

Should I also do it this way: open the database, get the cursor, close the database ?!

I mean, I don’t have any problems because I don’t do it, but ...

I need advice from experts, advice from you

+3
source share
3 answers

onCreate onDestroy. , , "" .

, , , "startManagingCursor" , . , , , . , , , .

.

+2

.

0

do not consider using finalize () to close a database connection. there is no guarantee when it will be called, or even if it is ever called. see Effective Java, second edition 7, for more information.

Is it possible to use onPause (), onResume () to close or open a connection? I believe that android gives some guarantee that they are called.

0
source

Source: https://habr.com/ru/post/1768617/


All Articles