BT

Your opinion matters! Please fill in the InfoQ Survey!

Android Architecture Components 1.0: Lifecycle, LiveData, ViewModel and Room

| by Abel Avram Follow 4 Followers on Nov 09, 2017. Estimated reading time: 1 minute |

Google has made available Android Architecture Components 1.0, a collection of libraries to design “robust, testable, and maintainable apps.” The current components are Lifecycle, LiveData, ViewModel and Room with others on the way.

Google has created Architecture Components to help with “persist data, manage the lifecycle of components, write modular applications, defense against common errors, write less boilerplate code.” The main components are:

Lifecycle is an architectural component used to create activities and fragments aware of their lifecycle, capable of adjusting their behavior based on their state. Components can go through multiple states – initialized, created, started, resumed, destroyed – and the lifecycle methods are called to perform various operations when a state event is triggered. Lifecycle will hold information about the status of a component, dealing with changes in status, and relieving the component of this tasks. The purpose is to write simpler code, easier to understand.

LiveData is an observable data holder class. LiveData is aware of the lifecycle of a component and provides updates when they are in an active state. LiveData is recommended to build reactive UIs.

ViewModel is another architectural component used to hold and manage data for activities or fragments, data which is preserved when the UI component is recreated in response to various user actions such as screen rotation. ViewModel is meant to hold some data-related code, resulting in the simplification of UI controllers.

Room is an object-mapping layer storing data in SQLite. Room includes query verification during compilation, to mark queries that might be erroneous. Google recommends using Room instead of directly accessing SQLite because data can be cached locally and it is integrated with LiveData, making it part of the component’s lifecycle.

In the near future, a new component will be made available, PagedList, which currently is in alpha. PageList is useful to gradually load data without waiting for large database queries to finish. They are also working on other architectural components that will be announced in the coming months.

Google has published Architecture Guidelines that explain how to use these components. They say the libraries are “ready for production” use, recommending using them to build Android applications.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT