This presentation is all about Android Architecture Components, their use cases and how they can decrease development time for android developers. It talks about LiveData, Room (Persistence Layer), Lifecycle and ViewModel & reftrofit.
2. Architecture
• What is architecture
• Why is architecture required?
• How architecture is different from design?
• Popular architectural patterns
• MVC
• MVP
• MVVM
• VIPER
3. Android Architecture Components
• Google’s official guidelines to architect your Android applications
• Reduce boilerplate
• Separation of concerns
• Testability
• Maintainability
• Ease of Implementation
4. Android Architecture
Components
• Activities/Fragments
• Represents View Layer
• Handle UI events
• ViewModel
• Observes View lifecycle events
• Bring data from Repository and update
Views
• Uses LiveData to observe changes to
the data in repository
• Repository
• Brings data from sqlite using Room
• Brings data from services
5. Lifecycle
• Problems without lifecycle
• Sometimes services starts after activity stops, for example a long running
code is being executed in onStart and after that a particular
component/service is started
• In that case component/service is alive when it shouldn’t be
• Lifecycle solves this problem with events and states
• Component can be made lifecycle aware with the help of following
• LifeCycleObserver
• LifeCycleOwner
6. ViewModel
• View Model is designed to store and manage UI related data in
lifecycle conscious way
• Idea is same, keep Views free from fetching and managing any data
• ViewModel survives configuration changes such as screen resolutions
• ViewModel must not reference a view
• If you need context in a ViewModel, use AndroidViewModel class
8. LiveData
• LiveData is an observable data holder class
• LiveData is lifecycle aware
• Lifecycle awareness ensures LiveData only update app components
observers that are in active lifecycle state
• Ensure UI is consistent with data
• Sharing resources
• Enduring configuration changes
9. Room
• Room persistence library provides an abstraction layer over sqlite
• It helps you create a cache of your app’s data on a device running
your app
• This cache acts as a system of record or single source of truth
• Provides an ORM capability with annotations and compile time code
generation
• Remove boilerplate code for creating DAO