I’m seeing following issue with LiveData and `view...
# android
a
I’m seeing following issue with LiveData and
viewLifecycleOwner.lifecycleScope.launch
If I’m trying to update live data in my VM from
.value
other fragments with same VM do not get it from observer. I have to use
postValue
and in that case it delivered properly. Does anyone know why could it be? Previously I have been using
uiScope
Copy code
uiScope = CoroutineScope(Dispatchers.Main + job)
to launch coroutines inside my fragments and it was working fine with
.value
but after I switched to
viewLifecycleOwner.lifecycleScope
it is not anymore.
h
Maybe, each Fragment has its own
viewLifecycleOwner.lifecycleScope
and they can't see each other. So you can't publish a value inside one scope and expect to receive in another from another fragment
maybe I'm wrong, I'm just trying to undertand better your problem
🙂
s
What do you mean by other fragments? How ate these fragments grouped, In a viewpager? In a nav graph? Or simply being replaced manually by using a fragment manager?
a
I have activity that inject fragments… I manually replacing fragments inside it. VM is tight to activity instance and is the same for all the fragments, since they are getting shared instance.