Error Handling & UX
Model UI states with sealed classes (Loading/Success/Error). Show ProgressBar, Snackbar with Retry actions, and inline TextInputLayout validation errors.
Why Error Handling Matters
Apps that crash or freeze without explanation feel broken. Users don't know what happened or what to do next.
Good error handling means:
- The app stays stable
- Users get a clear message
- They can retry or take action
This is the difference between a 2-star and a 5-star app review.
Modeling UI State
A clean pattern: model all possible UI states with a sealed class:
Loading— request is in progressSuccess(data)— data is availableError(message)— something went wrong
The ViewModel emits one of these states; the UI renders it.