https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
s

Smorg

08/26/2021, 8:23 AM
Hi, any ideas which flow constructs could produce the following behaviour: • keeps its latest value (as
StateFlow
behaves), but once that value is consumed, it no longer has any value (until it receives another and the cycle continues).
d

divid3d

08/26/2021, 8:44 AM
Maybe
SharedFlow
is what you might looking for.
s

Smorg

08/26/2021, 9:12 AM
yes, I have read about
SharedFlow
, but it doesn’t satisfy this requirement AFAICT • with a replay value of 1, it is always going to keep and re-emit that 1 value if a new subscriber subscribes, but it is required for it not to keep that value if it receives it while there is a subscriber. • with a replay value of 0, it is never going to keep any value, but it is required for it to keep 1 value when there are no subscribers.
s

solidogen

08/26/2021, 9:23 AM
you want a plain Channel
it suspends until a value is received
(not BroadcastChannel)
just keep in mind that you can’t have multiple subscribers this way
s

Smorg

08/26/2021, 9:30 AM
Thanks @solidogen. I’ll take a look, maybe that’s just what I need.
m

mario

09/02/2021, 9:54 AM
Do you want this for to do a navigation? I have a problem with this, my viewmodel has a sealed class with destinies of navigations, for example navigateToMain , navigateToLanding and this is a problem because when i press back button the behavior is go back an go foward again ( the stateflow is readed again)
2 Views