Hi, any ideas which flow constructs could produce ...
# android-architecture
s
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
Maybe
SharedFlow
is what you might looking for.
s
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
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
Thanks @solidogen. I’ll take a look, maybe that’s just what I need.
m
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)