Ever seen the same toast pop up again after a screen rotation? Or a navigation event fire twice? That’s a common problem when using LiveData for Android.

Challenge:

LiveData can re‑emit its last value on configuration changes, causing duplicate toasts or navigation events.

Solution:

Wrap events in a consumable Event class or use Kotlin Channels/Flow for single-shot events.

kotlin
open class Event<out T>(private val content: T) { private var handled = false fun getContentIfNotHandled(): T? = if (handled) null else { handled = true; content }
}
// In ViewModel
private val _navigate = MutableLiveData<Event<NavDirections>>()
val navigate: LiveData<Event<NavDirections>> = _navigate

Conclusion:

When you only want an event to happen once, don’t rely on plain LiveData. Wrapping your data in an Event class or using Kotlin’s Flow or Channels helps you avoid glitches like duplicate toasts or repeated navigation. If this kind of clean architecture matters to your app, it’s worth having experienced Android engineers on your team who know how to handle these edge cases correctly.