# Representing ViewModel events with StateFlow vs. SharedFlow vs. Channel

DevFeed: [Representing ViewModel events with StateFlow vs. SharedFlow vs. Channel](<https://devfeed.tech/articles/representing-viewmodel-events-with-stateflow-vs-sharedflow-vs-channel-39393.md>)

Original publisher: [Read original article](<https://kt.academy/article/viewmodel-stateflow-sharedflow-channel>)

Published: 2024-11-18T00:00:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [channel](<https://devfeed.tech/tags/channel.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [navigation](<https://devfeed.tech/tags/navigation.md>), [sharedflow](<https://devfeed.tech/tags/sharedflow.md>), [stateflow](<https://devfeed.tech/tags/stateflow.md>), [toast](<https://devfeed.tech/tags/toast.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

## AI overview

This article compares StateFlow, SharedFlow, and Channel for representing events in an Android ViewModel. It explains why StateFlow can lose events, notes SharedFlow's behavior when no UI observer is present, and discusses using an unlimited-capacity Channel as an event queue.

## Source excerpt

What is the best way to represent ViewModel events in Kotlin?