Hi guys, I’m still pretty new to Coroutines and wa...
# coroutines
m
Hi guys, I’m still pretty new to Coroutines and was wondering if anyone can let me know if I’m on the right track for what I want. Problem: I’m currently building out an Android application and I have several screens that require the User’s Location. This application can have multiple Activities/Fragments in its backstack. If the user changes their location on a screen, I would want every screen in the backstack to get that updated location object as well. Question: Looking into
Flows
, is a
channelFlow
what I need for my particular use-case? There would be one singular source-of-truth that multiple call sites will be subscribing to for the User’s location and would be a cold stream as the location would only be updated based on a method invocation.
l
Why you want to solve it by flow? Would eventbus solve your issue?
The issue is not very clear. If you really want to look into flow. I assume you have a singleton class handle the location logic. You should bind livedata -> your flow(if any) -> location value. And keep these livedatas in viewmodel of each activities or fragments.
flow.asLiveData()
is a useful extension function in the new 
androidx.lifecycle
 ktx packages, BTW.
👍 1
❤️ 1
m
If I have a fragment that makes a function call from a Singleton repository class that returns a flow that is bound to a live data then make that function call again from another fragment that emits a new location, would the first fragment receive the change?
"Why you want to solve it by flow? Would eventbus solve your issue?" Would it be possible to implement an event bus without the use of RX? The code base I'm currently working on is looking to move away from it
l
I use eventbus within kotlin.
m
Taking a look and it's possible I may be able to utilize Broadcast Channel
💯 2