Click here to view the Chinese introduction video: v.qq.com/x/page/r050…
Android runs on billions of devices, from high-end phones to in-flight video and entertainment systems. The Android OS, on the other hand, keeps billions of devices running, managing resources efficiently, and sometimes making it harder to develop great apps. To simplify the development process, we released a preview of Architecture Components at Google I/O, which provides guidelines for developing App architectures and a set of libraries for common tasks such as lifecycle management, data persistence, and more. With the help of these basic components, developers can write modular apps with less boilerplate code and focus on innovation rather than repetitive manual labor — and we will continue to improve this infrastructure in the future.
Today we are pleased to announce the 1.0 stable release of the Room and Lifecycles Architecture Component Library, with apis that are now available for use in production apps and libraries. We strongly recommend using these apis (recommended, not required) for developers who need help with App architecture and local storage. Lifecycle management is also integrated into the Support Library, so developers can also use these apis in standard categories such as AppCompatActivity.
Although we just released the stable version today, the beta components have already been integrated into a billion downloads of the App. Architecture components help many top development teams, such as Zapppos, focus more time on more critical work.
Before the architecture components are released, we have our own implementation of the ViewModel, which is guaranteed to remain the same even after configuration changes using a Loader and Dependency Injection. We recently switched to the ViewModel implementation in the architecture component and got rid of the rework altogether, finding that we could spend more time on design, business logic, and testing than on boilerplate code or worrying about the Android lifecycle.
Architectural components provide simple, flexible, and actionable solutions to common problems faced by developers, allowing them to focus on creating a first-class user experience. Behind the scenes, we bundle together multiple core building units through the App Architecture guide.
Lifecycles
Every Android developer should have faced the lifecycle issue where the operating system starts, stops, and destroys activities. This means that developers need to manage component state specifically for different phases of the lifecycle, such as observables for updating the user interface. Lifecycles help developers create “lifecycle aware” components that manage their own Lifecycles, reducing the possibility of memory leaks and crashes. Lifecycle libraries are the basis for other architectural components, such as LiveData.
Learn more about Lifecycles:
Developer. The android. Google. Cn/topic/libra…
LiveData
LiveData is a core component of the observable lifecycle based on the observer pattern. LiveData is an Observable of the interface code (Observer). When the data held by LiveData changes, it informs the corresponding interface code to update. At the same time, LiveData holds a reference to the interface code at Lifecycle, which means that it updates when the interface code (LifecycleOwner) is resumed or resumed. The update stops when LifecycleOwner is destroyed. With LiveData, developers can easily build highly responsive user interfaces with greater security and performance.
Learn more about LiveData:
Developer. The android. Google. Cn/topic/libra…
ViewModel
The ViewModel separates the view’s data and logic from entities with lifecycle features, such as activities and fragments. The ViewModel does not disappear until the associated Activity or Fragment is completely destroyed, that is, view data is retained even during events such as spinning the screen to cause the Fragment to be recreated. Not only do ViewModels eliminate common lifecycle problems, but they can also help build more modular user interfaces that are easier to test.
Learn more about ViewModel:
Developer. The android. Google. Cn/topic/libra…
Room
Almost all apps need to store data locally. Android has provided SQLite since its earliest versions, but using SQLite directly is a chore. Therefore, we introduced Room, a simple and easy to use object mapping layer. It’s just as powerful as SQLite, but saves a lot of coding hassle. Some of its features, such as data query validation at compile time and built-in migration support, make it easier for developers to build robust persistence layers. And Room can be integrated with LiveData, providing objects that can observe the database and feel the lifecycle. Room combines simplicity, power, and reliability to manage local storage so well that we highly recommend you try it out.
Learn more about Room:
Developer. The android. Google. Cn/topic/libra…
App Architecture guide and more
One final note: We have written an “App Architecture Guide,” which covers several key principles applicable to all developers, as well as specific guidance for architectural components. Because developers have told us that clear, consistent documentation is important, we have now updated the developer documentation to specify architectural components where appropriate. In addition, we have a series of videos, codelab and App samples posted on our website, with more to come.
App Architecture Guide:
Developer. The android. Google. Cn/topic/libra…
Android Architecture Components website:
Developer. The android. Google. Cn/topic/libra…
Continue to pay attention to this area
Although the first architectural components have been released in stable release, we know there is a long way to go. Over the past few months, we have been making serious improvements in response to your feedback. We also recently released a new component, PagedList, through the Alpha channel, to tackle the difficulty of using RecyclerView to process large data sets. The journey has only just begun, and we have many more important components in development that we expect to see in the coming months.
Learn more about PagedList:
Developer. The android. Google. Cn/topic/libra…
Submit feedback:
Developer. The android. Google. Cn/topic/libra…
We hope that architectural components will free up developers to focus on innovation and create unique new experiences for mobile. We are pleased to finally have a stable release ready for production. In particular, we would like to thank the developers for their valuable suggestions. Please feel free to leave comments in the discussion section below. For those of you who have been looking forward to the stable version, why don’t you download it today?