--

Thank you! :)

SingleLiveEvent can be replaced by SharedFlow. All events should be triggered from views, so there won't be and there shouldn't be any new events during configuration change. At the same time ViewModel, SharedFlow and StateFlow will survive the configuration change, so even if any event gets triggered then nothing will be lost. If you're concerned about your ShareFlow, you can always configure replay cache for your specific cases. Also, please keep in mind what is an event for you exactly. Events should be triggered from the UI to the ViewModel. The stuff that SingleLiveEvent was used before, in MVVM, can be replaced with Effects, using Channels for example. You can find more info here:

https://developer.android.com/kotlin/flow/stateflow-and-sharedflow

https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/

--

--

Patryk Kosieradzki
Patryk Kosieradzki

Written by Patryk Kosieradzki

Senior Android &iOS Engineer @ Moss, based in Warsaw, Poland

Responses (2)