I’m trying to communicate between an activity and ...
# coroutines
v
I’m trying to communicate between an activity and a fragment using a Conflated channel. I send a value to the channel from the activity before the fragment is initialized. Once initialized, the fragment should consume the value. But I would like the channel to no longer emit a value after the fragment consumes it. How do I do this?
r
use a flow instead of a channel?
v
I already consume the value as a flow. But send it through a channel
z
Why are you using a conflated channel?
v
I need a way to hold onto the value before the fragment is initialized. Would you recommend a Rendevouz channel or something else instead?
z
You could just give the channel a capacity of 1, then the initial send will succeed immediately, but once the value is received from the channel it won’t be received again.
v
You mean like so?
Copy code
val myChannel = Channel<String>(1)
z
yep!
d
If it's just one value I would recommend
CompletableDeferred
☝️ 1