Recently, I started to get involved in the MVVM architecture pattern in Android, and I also started to change from Java language to Kotlin language. I found that my technology stack was not enough, and now I also started to learn Jetpack in Android.
DataBinding (data binding): Bind data directly in XML and implement some processing logic to dynamically refresh data in real time
- Removed the code for updating UI data in activity and fragment
- Separate business logic and UI code
- Eliminate findViewById()
LiveData: It is an observable data holding class (data storage class), LiveData is life cycle aware
Lifecycle: easy to manage the life cycle of Activity and Fragment
ViewModel: Store and manage UI-related data in a lifecycle-aware way
The specific code is as follows: