Handling the UI State in Jetpack Compose and Using Hilt
All Android applications display the state to users, which helps inform users on what the outcome is and when. The state in an Android application is any value that changes over time, and a good example is a toast that shows a message when there is an error. In this chapter, readers will learn how to handle the UI state better with the new Jetpack library.
It is fair to say with great power comes great responsibility, and managing the state of any Composable component requires a distinct approach compared to using the older way of building Android views, or as many might call it, the imperative way. This means Jetpack’s library, Compose, is entirely different from XML layouts.
Handling the UI state in the XML View System is very straightforward. The process entails setting the properties of the views to reflect the current state – that is, showing or hiding the views accordingly. For instance, when loading...