Understanding the Jetpack ViewModel
While developing Android applications, you must have heard of the term ViewModel. If you haven't heard of it, then don't worry – this section aims to clearly illustrate what this component represents and why we need it in the first place.
To summarize, this section will cover the following topics:
- What is a ViewModel?
- Why do you need ViewModels?
- Introducing Android Jetpack ViewModel
- Implementing your first ViewModel
Let's start with the first question: what is this ViewModel
that we keep hearing about in Android?
What is a ViewModel?
Initially, the ViewModel
was designed to allow developers to persist UI state across configuration changes. In time, the ViewModel
became a way to also recover from edge cases such as system-initiated process death.
However, often, Android apps require you to write code that is responsible for getting the data from the server, transforming it, caching it, and...