tezvyn:

Why is LiveData<Boolean> bad for one-time ViewModel events?

Source: developer.android.comintermediate

Tests if you know LiveData holds state, not events. A good answer explains that LiveData re-emits on configuration changes, causing repeated events. The solution is to model events as part of the UI state and consume them.

This question tests your understanding of state vs. events in Android UI. LiveData is a state holder; it retains and re-emits its last value to new observers, like after a screen rotation, causing unwanted repeated actions (e.g., multiple Toasts). A senior answer explains this configuration change problem and proposes modeling events as part of the UI state, consumed via a dedicated function. A common but outdated answer is to suggest a custom SingleLiveEvent class without acknowledging its drawbacks.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Why is LiveData<Boolean> bad for one-time ViewModel events? · Tezvyn