Rihards
11/11/2022, 1:02 PMStateFlow
-> 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:
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:
updateChangesOnStart(changes: Flow<Int>) = changes
.onStart { emit(0) }
To update the state later I use:
scope.launch{
valueChanges.emit(${passed number})
}
Is the scope the one that does not allow me to update the value when function is reused?Young Rock
11/23/2022, 3:58 AMstateIn