Hi! I have an issue with `StateFlow` -> when I ...
# flow
r
Hi! I have an issue with
StateFlow
-> when I open the screen for the first time and do actions to emit new values then value is updated, but when I re-open the view then value is not updated to initial value, but old value is still there. This is the way I try to keep the state up to date:
Copy code
private val valueChanges: MutableSharedFlow<Int> = MutableSharedFlow(
  extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST
)

private val valueState: StateFlow<Int> = valueChanges
  .stateIn(scope, SharingStarted.Eagerly, 0)
Then at the very beginning of the whole flow I call this function where
changes
is
valueChanges
flow:
Copy code
updateChangesOnStart(changes: Flow<Int>) = changes
  .onStart { emit(0) }
To update the state later I use:
Copy code
scope.launch{
  valueChanges.emit(${passed number})
}
Is the scope the one that does not allow me to update the value when function is reused?
1
y
check the second param of
stateIn