Afzal Najam
01/17/2022, 11:38 PMonStop
, 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?heckfyxe
01/17/2022, 11:40 PMAfzal Najam
01/17/2022, 11:56 PMheckfyxe
01/18/2022, 12:16 AMAfzal Najam
01/18/2022, 1:20 AMHow about add to repository some checking is db authenticated or not? For example you can set db to null, when you close it, and return empty flow in repository if db is nullThanks, that’s a good idea! I’ll try to see if that works.
Alternatively you can not close db at all. Use boolean flag in Singleton and check it every onStart, set on onStop and in db creation by passphaseFeel like not closing the DB might make it a bit unsecure (insecure?), not sure but I’ll definitely try the first suggestion!