Erik Huizinga
May 17, 2021

No word about the SingleLiveEvent use case?

https://medium.com/androiddevelopers/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case-ac2622673150

That article currently links to an alternative article (https://proandroiddev.com/android-singleliveevent-redux-with-kotlin-flow-b755c70bb055, also see the responses) and promises that 'official guidance' is being written. I hoped that this article would be that official guidance! But there's not a word on events like UI messages and navigation events.

TLDR: use Channel<T>(Channel.BUFFERED) and fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T> for message events and Channel<T>(Channel.CONFLATED) and again receiveAsFlow() for navigation events, where T is your event type. No need for an event wrapper class or something. See also the excellent article from mister coroutine himself: https://elizarov.medium.com/shared-flows-broadcast-channels-899b675e805c, especially under 'A use-case for channels'.

Responses (2)