I have an app that’s using SQLCipher + Room and I want to ask the user for the password again when they return after leaving the app so I close the database. When they leave the single Activity app, in
onStop
, I close the database. When they return, I use the Navigation component to direct them to the Password Screen.
The screen with the list of data uses a
ViewModel
that exposes Flow from a Room DAO. The problem I’m having is that observing this from my
ItemList
Composable apparently leaks the DAO (and hence the Database instance) when the user leaves, and when the user unlocks the app again, the
ItemList
is still collection this Flow, which makes the app crash.
Using
asLiveData
on the
Flow
fixes the issue. Am I doing something wrong by observing the Room
Flow
from a
Composable
like this or is this some weird bug?