<https://stackoverflow.com/questions/75049173/flow...
# flow
f
You seem to be using State flow for events, which leads to the event being processed multiple times (whenever you re-subscribe to the flow). You need a means to consume the event so that you don't process it multiple times,
m
letus assume that is not an event and state like showing list on recycler view …. if u navigate to a activity/frgament then go back . showing list(submit list ) will be re executed. but live data has versioning feature which know which data is sent for a observer and will not send it again if value doesn’t changed
f
With state this works exactly as expected. When you come back the fragment view is recreated, you subscribe to the flow and update the list with the last emitted value.
n
Even if it is state, by wanting to only handle the value once, you are using it like an event, so use event APIs like SharedFlow or Channel. Haven't tried it but seems this could work for you:
stateFlow.produceIn(lifecycleScope).receiveAsFlow().flowWithLifecycle(lifecycle)
. The result should only emit changes while active but any state changes while inactive are kept in the conflated channel.