Summary
In this chapter, we analyzed the building blocks required to build a maintainable application. We also investigated one of the most common issues that developers come across when using the Android framework, which is maintaining the states of objects during life cycle changes.
We started by analyzing ViewModel
components and how they solve the issue of holding data during orientation changes. We added Flow
data streams to ViewModel
components to show how the two complement each other, and looked at how we can use other data streams with ViewModel
components and compare those with Flow
data streams.
We also looked at how we can save the instance state using ViewModel
components in combination with SavedStateHandle
, which transfers the responsibility of saving states from Activity
and Fragment
components to ViewModel
components.
We then moved on to Room to show how we can persist data with minimal effort and without much SQLite boilerplate code. We also explored...