SlideShare ist ein Scribd-Unternehmen logo
1 von 62
Downloaden Sie, um offline zu lesen
@orEssel
Ahalan
Android architecture AND architecture components
Mvvm
Building Mvvm with AAC
Saving UI state
Chaos
Mvvm
Part 1
• Design pattern
• Separation of concerns
• Components
• Communication
• Multiple definitions
Model - View - ViewModel
Holds Ui data, and exposes it via event / data streams (RX)
Abstracts the data source
Mvvm
Mvvm
Model - View - ViewModel
observes data from the viewModel
Display data
Delegates user actions to the viewModel
Dumb - No logic allowed!
Mvvm
Model - View - ViewModel
Holds ready to consume data, and exposes it to the consumer
Does not care who consumes its data.
Get user actions from view, and applies domain logic
View ViewModel Model
•ViewModel does not know the view/consumer of the data
•It encourages event driven/reactive programming
•View notify the viewModel about events
•Many to one relationship
•ViewModel does not know the view/consumer of the data
•It encourages event driven/reactive programming
•View notify the viewModel about events
•Many to one relationship
View ViewModel Model
•ViewModel does not know the view/consumer of the data
•It encourages event driven/reactive programming
•View notifies the viewModel about events
•Many to one relationship
View ViewModel Model
•ViewModel does not know the view/consumer of the data
•It encourages event driven/reactive programming
•View notify the viewModel about events
•Many to one relationship
View ViewModel Model
• Separation of concerns
• Clear and concise
• Communication
• Multiple definitions
This is the MVVM pattern
Android Architecture
Components
A collection of libraries that help you design robust,
testable, and maintainable apps
Part 2
• LifeCycle
• Live Data
• ViewModel
• Room
• Paging Library
• Navigation
• Work Manager
• Data binding
Recommended app architecture
Motivation
Problems
•Memory constraints
•Referring destroyed ui - memory leaks
•App moves from foreground - incoming phone call
•Configuration changes - rotation
Android designed to multitask
Let’s address those problems with AAC
lifeCycle awareness
LifeCycle-aware components perform actions in response to a
change in the lifecycle status of another component
LifeCycle
Holds the information about the lifecycle state of a component and
allows other objects to observe this state
We could approach this set of EVENTS and STATES as a
graph data structure.
LifeCycle
Event
ON_CREATE
ON_START
ON_PAUSE
ON_RESUME
ON_STOP
ON_DESTROY
ON_ANY
State
INITIALISEZED
CREATED
STARTED
RESUMED
DESTROYED
getLifecycle() : Lifecycle
AppCompatActivity
Fragment
ProcessLifeCycleOwner
LifeCycleService
LifeCycleOwner
ProcessLifecycleOwner
”Composite of all of your activities“
OnCreate - will be triggered only once.
OnDestroy will not be triggered.
class MyAmazingObserver : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun startDoSomething() {
//bla bla
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun stopDoSomething() {
//bla bla
}
}
LifeCycleObserver
class MyAmazingObserver : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun startDoSomething() {
//bla bla
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun stopDoSomething() {
//bla bla
}
}
lifecycle.addObserver(MyAmazingObserver())
LifeCycleObserver
class MyAmazingObserver : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun startDoSomething() {
lifeCycle.currentState.isAtLeast(Resumed)
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun stopDoSomething() {
//bla bla
}
}
lifecycle.addObserver(MyAmazingObserver())
LifeCycleObserver
LiveData
liveData, is a data holder class, which is lifeCycle aware.
It holds values, and allow them to be observed.
Emit events only if the observer is active!
Observer of LiveData is ACTIVE, if its Lifecycle.State is STARTED/
RESUMED. Otherwise, its considered as INACTIVE
val liveData : LiveData<String> = …
liveData.observe(this, Observer {
//bla bla
})
LiveData is LifeCycleAware
If observer will be destroyed - it will be removed
When LifeCycleOwner will return to ACTIVE state - it will be updated
MutableLiveData - update liveData objects
class MainViewModel : ViewModel() {
private val username = MutableLiveData<String>()
val userName: LiveData<String> get() = _username
fun updateUserNameMainThread() {
username.value = "Or Main Thread" // kotlin's setValue()
}
fun updateUserNameBackgroundThread() {
username.postValue("Or Background Thread!")
}
}
LiveData is immutable.
MediatorLiveData
Combining multiple LiveDataSources
private val networkErrors: LiveData<String> = ...
private val userUpdates: LiveData<User> = ...
val displayMessage = MediatorLiveData<String>()
displayMessage.addSource(userUpdates) { user ->
displayMessage.postValue("User ${user.name} added")
}
displayMessage.addSource(networkErrors) { errorMessage ->
displayMessage.postValue("Error $errorMessage")
}
Transformations.Map
Maybe we want to apply some FUNCTION on each emission.
val userLiveData: LiveData<User> = UserLiveData()
val userName: LiveData<String> =
Transformations.map(userLiveData) {
    user -> "${user.name} ${user.lastName}"
}
Transformations.Map
Maybe we want to apply some FUNCTION on each emission.
This function, would be calculated on UI thread, in a lazy way
val userLiveData: LiveData<User> = UserLiveData()
val userName: LiveData<String> =
Transformations.map(userLiveData) {
    user -> "${user.name} ${user.lastName}"
}
LiveData
• Ensures your UI matches your data state
• No memory leaks
• No crashes due to stopped activities
• No more manual lifeCycle handling
• Always up to date data
• Proper configuration changes
LifeCycle Aware - super power!
Survive configuration changes - super power!
Store and manage UI related data
Android’s ViewModel
viewModel
View
(activity/fragment)
Ui data
LiveData
viewModel
View
(activity/fragment)
Ui data
LiveData
viewModel
View
(activity/fragment)
new view
(activity/fragment)
Ui data
LiveData
We solved most of our problems - except for….
Saving Ui state
Part 3 - hold tight, it’s short!
Process death
• Empty processes
• Background processes
• Service processes
• Visible processes
• Foreground processes
onSavedInstanceState
• Smallest amount of data needed to restore ui state
onSavedInstanceState
• Smallest amount of data needed to restore ui state
• Search term for list of objects, such as conversations
• swipe away from multitask view
• Navigate back
• Explicit call to finish()
More death options
The user will not expect the ui to restore it’s state after they
have occurred.
Mvvm using Android architecture components
• Survive configuration changes
• LifeCycle aware
• Separation of concerns
• Reactive
Questions?
Thank you very much for listening!
@orEssel
Appendix
Guide to app architecture - https://developer.android.com/jetpack/docs/guide
Lecture by Lyla Fujiwara - https://www.youtube.com/watch?v=BofWWZE1wts
Lecture by Florina Muntenescu - https://www.youtube.com/watch?v=U6Lgym1XEBI
Android JetPack - https://developer.android.com/jetpack/
Architecture components - https://developer.android.com/topic/libraries/architecture/
Mvvm on Android - https://medium.com/upday-devs/android-architecture-patterns-part-3-model-view-viewmodel-e7eeee76b73b
Reactive architecture - https://medium.com/insiden26/reactive-clean-architecture-with-android-architecture-
components-685a6682e0ca

Weitere ähnliche Inhalte

Ähnlich wie Android architecture components - how they fit in good old architectural patterns - Or Essel, Guild of Free Programmers

Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture ComponentsDarshan Parikh
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture ComponentsBurhanuddinRashid
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architectureVitali Pekelis
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingYongjun Kim
 
Reduxing UI: Borrowing the Best of Web to Make Android Better
Reduxing UI: Borrowing the Best of Web to Make Android BetterReduxing UI: Borrowing the Best of Web to Make Android Better
Reduxing UI: Borrowing the Best of Web to Make Android BetterChristina Lee
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019UA Mobile
 
Android Architecture Components with Kotlin
Android Architecture Components with KotlinAndroid Architecture Components with Kotlin
Android Architecture Components with KotlinAdit Lal
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...Akira Hatsune
 
Observer-MVVM-RxJava
Observer-MVVM-RxJavaObserver-MVVM-RxJava
Observer-MVVM-RxJavaRıdvan SIRMA
 
Ios development 2
Ios development 2Ios development 2
Ios development 2elnaqah
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its featuresAbhishek Sur
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVMAbhishek Sur
 
iOS Architectures
iOS ArchitecturesiOS Architectures
iOS ArchitecturesHung Hoang
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 
ReSwift & Machine Learning
ReSwift & Machine LearningReSwift & Machine Learning
ReSwift & Machine LearningRodrigo Leite
 
Hello, ReactorKit 
Hello, ReactorKit Hello, ReactorKit 
Hello, ReactorKit Suyeol Jeon
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 

Ähnlich wie Android architecture components - how they fit in good old architectural patterns - Or Essel, Guild of Free Programmers (20)

Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architecture
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and Testing
 
Reduxing UI: Borrowing the Best of Web to Make Android Better
Reduxing UI: Borrowing the Best of Web to Make Android BetterReduxing UI: Borrowing the Best of Web to Make Android Better
Reduxing UI: Borrowing the Best of Web to Make Android Better
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019
 
Android Architecture Components with Kotlin
Android Architecture Components with KotlinAndroid Architecture Components with Kotlin
Android Architecture Components with Kotlin
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
 
Observer-MVVM-RxJava
Observer-MVVM-RxJavaObserver-MVVM-RxJava
Observer-MVVM-RxJava
 
Android
AndroidAndroid
Android
 
Ios development 2
Ios development 2Ios development 2
Ios development 2
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
iOS Architectures
iOS ArchitecturesiOS Architectures
iOS Architectures
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
ReSwift & Machine Learning
ReSwift & Machine LearningReSwift & Machine Learning
ReSwift & Machine Learning
 
Hello, ReactorKit 
Hello, ReactorKit Hello, ReactorKit 
Hello, ReactorKit 
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 

Mehr von DroidConTLV

Mobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeMobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeDroidConTLV
 
Doing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDoing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDroidConTLV
 
No more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsNo more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsDroidConTLV
 
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comMobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comDroidConTLV
 
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellLiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellDroidConTLV
 
MVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, LightricksMVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, LightricksDroidConTLV
 
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)DroidConTLV
 
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaBuilding Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaDroidConTLV
 
New Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovNew Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovDroidConTLV
 
Designing a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDesigning a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDroidConTLV
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperDroidConTLV
 
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevKotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevDroidConTLV
 
Flutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalFlutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalDroidConTLV
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisDroidConTLV
 
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelFun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelDroidConTLV
 
DroidconTLV 2019
DroidconTLV 2019DroidconTLV 2019
DroidconTLV 2019DroidConTLV
 
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayOk google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayDroidConTLV
 
Introduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixIntroduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixDroidConTLV
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneDroidConTLV
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirDroidConTLV
 

Mehr von DroidConTLV (20)

Mobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeMobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, Nike
 
Doing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDoing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra Technologies
 
No more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsNo more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola Solutions
 
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comMobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
 
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellLiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
 
MVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, LightricksMVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, Lightricks
 
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
 
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaBuilding Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
 
New Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovNew Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy Zukanov
 
Designing a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDesigning a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, Gett
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
 
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevKotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
 
Flutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalFlutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, Tikal
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
 
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelFun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
 
DroidconTLV 2019
DroidconTLV 2019DroidconTLV 2019
DroidconTLV 2019
 
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayOk google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
 
Introduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixIntroduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, Wix
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Android architecture components - how they fit in good old architectural patterns - Or Essel, Guild of Free Programmers

  • 1.
  • 3. Android architecture AND architecture components Mvvm Building Mvvm with AAC Saving UI state
  • 5. Mvvm Part 1 • Design pattern • Separation of concerns • Components • Communication • Multiple definitions
  • 6. Model - View - ViewModel Holds Ui data, and exposes it via event / data streams (RX) Abstracts the data source Mvvm
  • 7. Mvvm Model - View - ViewModel observes data from the viewModel Display data Delegates user actions to the viewModel Dumb - No logic allowed!
  • 8. Mvvm Model - View - ViewModel Holds ready to consume data, and exposes it to the consumer Does not care who consumes its data. Get user actions from view, and applies domain logic
  • 9. View ViewModel Model •ViewModel does not know the view/consumer of the data •It encourages event driven/reactive programming •View notify the viewModel about events •Many to one relationship
  • 10. •ViewModel does not know the view/consumer of the data •It encourages event driven/reactive programming •View notify the viewModel about events •Many to one relationship View ViewModel Model
  • 11. •ViewModel does not know the view/consumer of the data •It encourages event driven/reactive programming •View notifies the viewModel about events •Many to one relationship View ViewModel Model
  • 12. •ViewModel does not know the view/consumer of the data •It encourages event driven/reactive programming •View notify the viewModel about events •Many to one relationship View ViewModel Model
  • 13. • Separation of concerns • Clear and concise • Communication • Multiple definitions This is the MVVM pattern
  • 14. Android Architecture Components A collection of libraries that help you design robust, testable, and maintainable apps Part 2
  • 15. • LifeCycle • Live Data • ViewModel • Room • Paging Library • Navigation • Work Manager • Data binding
  • 18. Problems •Memory constraints •Referring destroyed ui - memory leaks •App moves from foreground - incoming phone call •Configuration changes - rotation Android designed to multitask Let’s address those problems with AAC
  • 19. lifeCycle awareness LifeCycle-aware components perform actions in response to a change in the lifecycle status of another component
  • 20.
  • 21. LifeCycle Holds the information about the lifecycle state of a component and allows other objects to observe this state We could approach this set of EVENTS and STATES as a graph data structure.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. ProcessLifecycleOwner ”Composite of all of your activities“ OnCreate - will be triggered only once. OnDestroy will not be triggered.
  • 38. class MyAmazingObserver : LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) fun startDoSomething() { //bla bla } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) fun stopDoSomething() { //bla bla } } LifeCycleObserver
  • 39. class MyAmazingObserver : LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) fun startDoSomething() { //bla bla } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) fun stopDoSomething() { //bla bla } } lifecycle.addObserver(MyAmazingObserver()) LifeCycleObserver
  • 40. class MyAmazingObserver : LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) fun startDoSomething() { lifeCycle.currentState.isAtLeast(Resumed) } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) fun stopDoSomething() { //bla bla } } lifecycle.addObserver(MyAmazingObserver()) LifeCycleObserver
  • 41. LiveData liveData, is a data holder class, which is lifeCycle aware. It holds values, and allow them to be observed. Emit events only if the observer is active!
  • 42. Observer of LiveData is ACTIVE, if its Lifecycle.State is STARTED/ RESUMED. Otherwise, its considered as INACTIVE val liveData : LiveData<String> = … liveData.observe(this, Observer { //bla bla }) LiveData is LifeCycleAware If observer will be destroyed - it will be removed When LifeCycleOwner will return to ACTIVE state - it will be updated
  • 43. MutableLiveData - update liveData objects class MainViewModel : ViewModel() { private val username = MutableLiveData<String>() val userName: LiveData<String> get() = _username fun updateUserNameMainThread() { username.value = "Or Main Thread" // kotlin's setValue() } fun updateUserNameBackgroundThread() { username.postValue("Or Background Thread!") } } LiveData is immutable.
  • 44. MediatorLiveData Combining multiple LiveDataSources private val networkErrors: LiveData<String> = ... private val userUpdates: LiveData<User> = ... val displayMessage = MediatorLiveData<String>() displayMessage.addSource(userUpdates) { user -> displayMessage.postValue("User ${user.name} added") } displayMessage.addSource(networkErrors) { errorMessage -> displayMessage.postValue("Error $errorMessage") }
  • 45. Transformations.Map Maybe we want to apply some FUNCTION on each emission. val userLiveData: LiveData<User> = UserLiveData() val userName: LiveData<String> = Transformations.map(userLiveData) {     user -> "${user.name} ${user.lastName}" }
  • 46. Transformations.Map Maybe we want to apply some FUNCTION on each emission. This function, would be calculated on UI thread, in a lazy way val userLiveData: LiveData<User> = UserLiveData() val userName: LiveData<String> = Transformations.map(userLiveData) {     user -> "${user.name} ${user.lastName}" }
  • 47. LiveData • Ensures your UI matches your data state • No memory leaks • No crashes due to stopped activities • No more manual lifeCycle handling • Always up to date data • Proper configuration changes
  • 48. LifeCycle Aware - super power! Survive configuration changes - super power! Store and manage UI related data Android’s ViewModel
  • 52.
  • 53. We solved most of our problems - except for….
  • 54. Saving Ui state Part 3 - hold tight, it’s short!
  • 55. Process death • Empty processes • Background processes • Service processes • Visible processes • Foreground processes
  • 56. onSavedInstanceState • Smallest amount of data needed to restore ui state
  • 57. onSavedInstanceState • Smallest amount of data needed to restore ui state • Search term for list of objects, such as conversations
  • 58. • swipe away from multitask view • Navigate back • Explicit call to finish() More death options The user will not expect the ui to restore it’s state after they have occurred.
  • 59. Mvvm using Android architecture components • Survive configuration changes • LifeCycle aware • Separation of concerns • Reactive
  • 60. Questions? Thank you very much for listening!
  • 62. Appendix Guide to app architecture - https://developer.android.com/jetpack/docs/guide Lecture by Lyla Fujiwara - https://www.youtube.com/watch?v=BofWWZE1wts Lecture by Florina Muntenescu - https://www.youtube.com/watch?v=U6Lgym1XEBI Android JetPack - https://developer.android.com/jetpack/ Architecture components - https://developer.android.com/topic/libraries/architecture/ Mvvm on Android - https://medium.com/upday-devs/android-architecture-patterns-part-3-model-view-viewmodel-e7eeee76b73b Reactive architecture - https://medium.com/insiden26/reactive-clean-architecture-with-android-architecture- components-685a6682e0ca