What is the alternative using flow or channel for ...
# coroutines
What is the alternative using flow or channel for SingleLiveEvent in this situation:
Copy code
val onSuccess = SingleLiveEvent<Unit>()

fun load() {
    // do something
Some points about using SharedFlow for dispatching single events: - Events are lost when there are no subscribers - Multiple subscribers will all receive the same event
Like the others said, you can use a SharedFlow with replay = 0 so that the new value will be emitted only once and not repeated
I don’t like using SharedFlow on Android to handle “events”. I like to use a channel with
so that on configuration change if an event is emitted with no observers it’s not dropped. (The channel buffers while there are no observers while SharedFlow is hot.) There are some caveats when doing that though. https://medium.com/@elizarov/shared-flows-broadcast-channels-899b675e805c Has a really good explanation of that “single shot event” use case.
☝️ 1