The role of jetpack common architecture components

Recently, I am preparing to write a new Android application, and I want to try to use the architecture components in jetpack. The components here can be used alone, and each has its own role, so according to your current understanding, make a record to avoid forgetting. Continually updated

The role of viewmodel:
1. Activity will be recreated when flipping, language changes, etc., resulting in data loss, and data stored in viewmodel will be automatically saved.
2. After using the MVVM architecture, the data and operations on the data are extracted to the VM to reduce the complexity of the activity code

The function of databinding:
1. After use, each activity will automatically generate ActivityXxxBinding class, which contains references to controls, no need to use findviewbyId. It not only reduces the code, but also prevents the error that findviewbyId is empty or uninitialized due to interface modification, because after binding, the reference error can be found automatically during compilation.
2. It can be directly bound to data or methods in the VM, reducing java code binding.

livedata
1. Observer mode, after the data changes, the UI is automatically updated. Reduce the coupling between the interface and the Controller, and the interface View is only associated with the VM.

room
1. Object-relational data persistence ORM, write object storage, can verify object and SQL errors

Navigation
1. Write all interfaces in one activity and manage them through fragments. It is necessary to maintain an additional graph xml
2. Graphically see the jump relationship of each interface, and also support safe parameter transfer and animation

paging
not used yet

workmanager
is not used yet

An upgraded version of UI constrainlayout
relativelayout, see that it supports setting guideline, barrier auxiliary positioning, and also supports combined controls, various alignments, etc. It is more conducive to IDE to write controls
 

おすすめ

転載: blog.csdn.net/sd2131512/article/details/117571883