Learn about Jetpack in half an hour

In Google's official documentation, Jetpack is defined like this:

Jetpack 是一套组件库,可帮助开发人员遵循最佳实践,减少样板代码并编写可在 Android 版本和设备上
一致工作的代码,以便开发人员可以专注于他们关心的代码。

According to the definition, two core points can actually be extracted:

  1. It is a set of component libraries . (Indicating that it is composed of many different component libraries, not a single component library)
  2. Using Jetpack can help us achieve consistent working code across different Android versions and different devices. (It shows that Jetpack can easily handle the differences and compatibility issues caused by inconsistent Android versions and different devices)
    Jetpack architecture diagram

The following briefly introduces the components of Jetpack

LifeCycle has the LifeCycle component. When the life cycle of the system components Activity, Fragment, Service and Application changes, our custom components can be notified in time. LifeCycle further decouples our custom and system components

Navigation handles everything needed for the navigation map, including page jumps, parameter transfers, animation effect settings, and App bar settings, etc. The navigation graph allows us to stand in the "God's perspective" and overlook the relationship between all interfaces of the application.

ViewModel is responsible for handling the business logic between View and Model. It is directly responsible for the data required by the UI, allowing the separation of view and data. Moreover, ViewModel is related to the life cycle, and it can automatically handle the data reacquisition problem caused by the re-creation of the interface due to screen rotation.

LiveData LiveData plays an important role between the layers of the MVVM architecture. When the data changes, the subscribers of the data can be notified through LiveData.

Room Google's official ORM database, natively supports LiveData. When using Livedata, when the data in the Room database changes, LiveData enables data subscribers to be notified in a timely manner without re-acquiring data from the database.

WorkManager provides a unified solution for those tasks in the application that do not need to be completed in a timely manner.

DataBinding further decouples the UI interface. The emergence of DataBinding makes findViewById no longer exist, so that layout files can take on more work, and even some simple business logic, which reduces the workload of Activity and Fragment.

Paging provides a unified solution for the three common paging mechanisms, enabling engineers to focus a lot of energy on business code.

Reference Document
1 https://zhuanlan.zhihu.com/p/334350927
2 Android Jetpack Application Guide by Ye Kun

Guess you like

Origin blog.csdn.net/wudexiaoade2008/article/details/121618985