Model Android UI state
Give a Compose screen explicit loading, content and error states.
Describe the screen from state
In Jetpack Compose, composable functions describe the UI for the current state. A list screen may be loading, show entries, show an empty result, or report a failure. Model these differences so that a composable can render the correct view.
How it works
Draw the screen at four moments: before results arrive, when data is ready, when there is no data, and when the request fails. Decide which actions are available in each state. This prevents old values and new error messages from appearing together by accident.
Keep events and rendering clear
Handle user events such as Retry where the state changes. Let the screen receive its display state and callbacks so it is easier to preview in isolation. Decide which inputs to preserve across device rotation and which must persist across app launches.
Further reading
Check your understanding
Decide which user-visible state to show when the app receives a successful response with zero results.
See the example and explanation
- Example 1
- Given
Success with zero entries - Answer
Empty view
Render an empty state that explains there are no entries and, where relevant, offers the next action. A loading state would suggest that more data is on the way.