Android Architecture Components
Android Architecture Components is new collection of libraries that help you design robust, testable, and maintainable apps. Main parts are: Lifecycles, ViewModel, LiveData, Room.
Add Architecture Components
Application build gradle
Custom Lifecycle-aware component
Each UI component lifecycle changed as shown at image.
You may create component, that will be notified on lifecycle state change:
You may write custom LiveData, if you need custom logic.
Don't write custom class, if you only need to transform data (use Transformations class)
Room require four parts: Database class, DAO classes, Entity classes and Migration classes (now you may use only DDL methods):
Use in Application class or provide via Dagger
Write your repository:
Use in ViewModel:
Using Lifecycle in AppCompatActivity
Extend your activity from this activity
ViewModel with LiveData transformations
Somewhere in UI:
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0