SlideShare a Scribd company logo
Architecture Components
+ Diego Nascimento
Software Engineer at CESAR
What are the goals of these "architecture components" ?
Architecture Components - API
- Room
- ViewModel
- LiveData
- Lifecycle
* Taken from the book O'Reilly Head First "Design Patterns"
The one who is listening is Observer...
And the other one, who is emitting events, is subject or observable.
LiveData
public LiveData<Films> getFilms() {
final MutableLiveData<Films> data = new MutableLiveData<>();
webService.getFilms().enqueue(new Callback<Films>() {
@Override
public void onResponse(Call<Films> call, Response<Films> response) {
data.setValue(response.body());
}
});
return data;
}
// Update the list when the data changes
viewModel.getFilms().observe(this, new Observer<Films>() {
@Override
public void onChanged(@Nullable Films films) {
if (films != null) {
lstFilms.setAdapter(new FilmsAdapter(getApplicationContext(), films.results);
}
});
Configuration Change
onCreate
onStart
onResume
onPause
onStop
onDestroy
onStart
onResume
onCreate
Activity Created
Activity Rotated
onCleared
ViewModel Scope
ViewModel
The ViewModel class is designed to store and manage UI-related
data so that the data survives configuration changes such as
screen rotations.
public class MyViewModel extends ViewModel {
private MutableLiveData<List<User>> users;
public LiveData<List<User>> getUsers() {
if (users == null) {
users = new MutableLiveData<List<Users>>();
loadUsers();
}
return users;
}
private void loadUsers() {
// do async operation to fetch users
}
}
public void onCreate(Bundle savedInstanceState) {
MyViewModel model = ViewModelProviders.of(this).get(MyViewModel.class);
model.getUsers().observe(this, users -> {
// update UI
});
}
Handling Lifecycle
The android.arch.lifecycle package provides classes and interfaces that let
you build lifecycle-aware components — which are components that can
automatically adjust their behavior based on the current lifecycle of an
activity or fragment
LifecycleOwner
LifecycleOwner is a single method interface that denotes that the class has a
Lifecycle. It has one method, getLifecycle(), which must be implemented by the
class.
public class MyFragment extends Fragment implements LifecycleRegistryOwner {
LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
@Override
public LifecycleRegistry getLifecycle() {
return lifecycleRegistry;
}
}
LifecycleObserver
LifecycleObserver observe LifecycleOwners, and are notified of lifecycle changes.
public class MyObserver implements LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void onPause() {
}
}
aLifecycleOwner.getLifecycle().addObserver(new MyObserver());
See more...
https://developer.android.com/topic/libraries/architecture/index.htm
l
https://www.youtube.com/watch?v=FrteWKKVyzI&list=PLOU2XLYxm
sIKC8eODk_RNCWv3fBcLvMMy&t=1886s&index=13

More Related Content

PDF
Android Architecture components
PPTX
Presentation Android Architecture Components
PDF
Eclipse MicroProfile para o desenvolvedor ocupado
PDF
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
PPTX
Android Architecture - Khoa Tran
PDF
Eclipse MicroProfile metrics: Practical use cases
PDF
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
PPT
Using xUnit as a Swiss-Aarmy Testing Toolkit
Android Architecture components
Presentation Android Architecture Components
Eclipse MicroProfile para o desenvolvedor ocupado
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Android Architecture - Khoa Tran
Eclipse MicroProfile metrics: Practical use cases
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Using xUnit as a Swiss-Aarmy Testing Toolkit

What's hot (19)

KEY
SQLite 周りのテストをしよう
PDF
SOLID principles with Typescript examples
PDF
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
PPTX
Rx for Android & iOS by Harin Trivedi
PPTX
Puppet Camp Melbourne 2014: Node Collaboration with PuppetDB
PDF
Modern Android app library stack
PDF
Saving lives with rx java
PDF
Eclipse MicroProfile para el desarrollador ocupado
PDF
Data backup
PDF
Introduction to Retrofit and RxJava
PDF
Creating image thumbnails in asp.net
PDF
Don't Make Android Bad... Again
PDF
The Singleton Pattern In Java
PPTX
Angular2 rxjs
PDF
Easy Scaling with Open Source Data Structures, by Talip Ozturk
PDF
iOS Development Methodology
PDF
Thunderstruck
PDF
Rxjs vienna
PDF
Js objects
SQLite 周りのテストをしよう
SOLID principles with Typescript examples
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Rx for Android & iOS by Harin Trivedi
Puppet Camp Melbourne 2014: Node Collaboration with PuppetDB
Modern Android app library stack
Saving lives with rx java
Eclipse MicroProfile para el desarrollador ocupado
Data backup
Introduction to Retrofit and RxJava
Creating image thumbnails in asp.net
Don't Make Android Bad... Again
The Singleton Pattern In Java
Angular2 rxjs
Easy Scaling with Open Source Data Structures, by Talip Ozturk
iOS Development Methodology
Thunderstruck
Rxjs vienna
Js objects
Ad

Similar to Android architecture components (20)

PDF
Architecture components - IT Talk
PDF
Architecture Components
KEY
Android workshop
PPTX
Android Architecture Components
PDF
Oleksandr Tolstykh
PDF
MobiConf 2018 | Room: an SQLite object mapping library
PPTX
Storage Plug-ins
PPTX
The Best Way to Become an Android Developer Expert with Android Jetpack
PPTX
CloudStack Meetup Santa Clara
PDF
Cleaning your architecture with android architecture components
PDF
Building Modern Apps using Android Architecture Components
PPTX
Realm - Phoenix Mobile Festival
PDF
Android data binding
KEY
SOLID Principles
PDF
Innovative Specifications for Better Performance Logging and Monitoring
PDF
Android Architecture Components with Kotlin
PDF
Clean Architecture on Android
PDF
Painless Persistence with Realm
PDF
Android Design Patterns
PDF
NetflixOSS season 2 episode 2 - Reactive / Async
Architecture components - IT Talk
Architecture Components
Android workshop
Android Architecture Components
Oleksandr Tolstykh
MobiConf 2018 | Room: an SQLite object mapping library
Storage Plug-ins
The Best Way to Become an Android Developer Expert with Android Jetpack
CloudStack Meetup Santa Clara
Cleaning your architecture with android architecture components
Building Modern Apps using Android Architecture Components
Realm - Phoenix Mobile Festival
Android data binding
SOLID Principles
Innovative Specifications for Better Performance Logging and Monitoring
Android Architecture Components with Kotlin
Clean Architecture on Android
Painless Persistence with Realm
Android Design Patterns
NetflixOSS season 2 episode 2 - Reactive / Async
Ad

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Nekopoi APK 2025 free lastest update
PPTX
assetexplorer- product-overview - presentation
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Digital Strategies for Manufacturing Companies
PDF
top salesforce developer skills in 2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
medical staffing services at VALiNTRY
PDF
Cost to Outsource Software Development in 2025
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
L1 - Introduction to python Backend.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Upgrade and Innovation Strategies for SAP ERP Customers
Nekopoi APK 2025 free lastest update
assetexplorer- product-overview - presentation
Navsoft: AI-Powered Business Solutions & Custom Software Development
CHAPTER 2 - PM Management and IT Context
Digital Strategies for Manufacturing Companies
top salesforce developer skills in 2025.pdf
Operating system designcfffgfgggggggvggggggggg
Why Generative AI is the Future of Content, Code & Creativity?
medical staffing services at VALiNTRY
Cost to Outsource Software Development in 2025
Computer Software and OS of computer science of grade 11.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Odoo Companies in India – Driving Business Transformation.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
L1 - Introduction to python Backend.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency

Android architecture components