A first question would be: Does a Room DB needs to be closed upon exiting an app?
I've tried to close the DB in onDestroy()
, but as I leave the app by pressing the back button and then
restart it either by using the launcher icon or recent apps window I get an error saying that the DB
is not opened. Only if I after leaving the app by pressing the back button I remove the app from
recent apps window by swiping up the app, I can launch the app from the launcher without any errors.
The second question would be: Is there any intermediate state of an app or the app's process once it's exited with the back button and not cleaned from the recent apps window?
Regarding this second question I've just stumbled upon this topic Is quitting an application frowned upon?, and if I got it right, once we leave the app (by pressing the back button) the app's process remain alive and it's left to the OS to decide when to fully shut it down? If this turns out to be the truth, I should be re-opening the DB in onCreate(), so the third question would be: How to re-open the closed Room DB?