I have a SQLite database declared and stored at the application level. I handle configuration changes such as device rotation, so closing the database I set it inside onDestroy MainActivity, but inside if (this.isFinishing ()).
The problem is that if, right after closing the application, I try to start it again, it will crash, informing me that it tried to open an already closed database. The next time it starts correctly. I think this is because Android never closed the application, because it was not necessary, and it is still in the background.
I could not find a way to detect onFinish / onDestroy .... at the application level to close the database there. The only workaround I can make is not to close the database. But this can lead to problems, perhaps when trying to open it again in case Android really closed my application, no?
Is there a way to force close the application? (I think not). Is there any way to detect application closure to close the database? Am I having trouble trying to open a closed database if the application was closed by Android? Or does Android close the database associated with the application that it is about to close?
source
share