How should I be replacing LiveData in a database c...
# flow
s
How should I be replacing LiveData in a database call with flow?
j
Room?
s
Hi Javier. The database is in Room. Replace LiveData<> with Flow<> as the datatype in the DAO. Use emit instead of postValue and collect instead of observe in the repository. Call the repository from the View Model and then call collect from the Fragment with GlobalScope.launch. Is that correct?
j
you have an extension function to transform the flow into livedata in the ViewModel
having your domain and data layer with Flow
if you want to replace livedata in the viewmodel with a flow, you should transform the flow into stateFlow for example
s
Thanks. I’ll look into extention functions and stateFlow
g
GlobalScope in Fragment doesn't sound right, you probably need lifecycleScope