Sanendak
04/07/2021, 5:31 PMprivate val _state = MutableStateFlow("initial")
val state: StateFlow<String> = _state
How i change state:
_state.value = "ringing"
How collected:
fun getCallLog() = flow<String> {
listenerService.state.collect {
Log.d("CALL STATE", it)
emit(it)
}
}
When I collect in the same place where I create StateFlow all works fine.baxter
04/07/2021, 5:46 PMval state: StateFlow<String> = _state.asStateFlow()
Then, instead of wrapping the state flow, you can just pass it back directly when you call getCallLog()
. Each time you collect the flow, it'll emit the latest item as well as all subsequent ones.fun getCallLog(): Flow<String> = listenerService.state.onEach { Log.d("CALL STATE", it) }
Sanendak
04/07/2021, 5:52 PM