https://kotlinlang.org logo
Title
a

aipok

05/28/2020, 1:58 PM
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
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

henrikhorbovyi

05/28/2020, 4:24 PM
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

Saurabh

05/29/2020, 4:43 AM
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

aipok

05/29/2020, 5:46 AM
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.