tezvyn:

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

Source: developer.android.comintermediate

WHAT IT TESTS: LiveData replays one-time events after rotation. A GOOD ANSWER COVERS: State is not events; suggest an Event wrapper with a consumed flag, or SharedFlow or Channel with no replay. RED FLAG: Praising SingleLiveEvent or onCleared resets as fix.

WHAT IT TESTS: Whether you know LiveData's sticky cache replays one-time events after configuration changes, blurring the line between UI state and ephemeral events. A GOOD ANSWER COVERS: Explain that LiveData<Boolean> is state, so rotation re-triggers Toasts or navigation; propose idiomatic fixes like an Event wrapper with a handled flag and getContentIfNotHandled, or migrating to SharedFlow or Channel with replay=0. RED FLAG: Calling SingleLiveEvent a perfect fix, or resetting flags in onCleared as a reliable solution.

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> problematic for one-time ViewModel events? · Tezvyn