Please enable JavaScript.
Coggle requires JavaScript to display documents.
Android (Android Architecture Component (UI Layer (ViewModel
Get…
Android
-
UI Layer
ViewModel
- Get destroyed when associated activity or fragment get completely destroyed
- Best Practice : No one can modify ViewModel data
- 1: Mark data as private,
- Backing Property: Return smt from getter other than the exact object
val score : LiveData<Int> get() = data
-
Problem
- If UI have initial data -> We have to pass initial data to ViewModel -> Solution
LiveData : Allow ViewModel communicate with UI
- lifecycle awareness : LiveData observe UI with LifecycleObserver
- LiveData know lifecycle state of it associated UI (fragment, activity) -> If UI is off-screen -> Data of livedata change -> LiveData won't notify UI to update (nothing done) -> when UI on-screen again -> livedata will notify newest data
- If new ui observe livedata -> It will get current lastest data
- If UI get destroyed, livedata will clean up all connection (observe) auto
Bug
- If we observer value of livedata to trigger an 1 time event (Navigate, show toast...) -> If we rotate -> That event will be triggered again.
-> Simple fix : After trigger that event -> We change data in livedata for not matching again when rotate
Features
- Can combine databinding with livedata, without UI code (observer, update value) : Solution
- With livedata that need to be manipulated before render, ex: Convert time to String (This logic shouldn't be in XML file) or more complex logic -> Use Transform
Data layer (Persistence)
Room : Resource
- SQL database
- Hỗ trợ real time via LiveData (Like Firestore)
- When update schema -> Have to update version so app can work properly
- Volalite -> Value của instance trỏ tới DB luôn up to date ở mọi thread, ko bị cache lại dẫn tới việc sai dữ liệu
- synchronize : Wrap phần getInsstance DB trong synchronize nhằm ám chỉ, chỉ 1 thread được access DB trong 1 khoảng thời gian. Khi code multiple thread có thể dẫn tới việc 2 thread cùng lúc gọi DB -> Có thể initialize 2 DB
- When create DB, have to set fallBackDestructiveMigration() -> Để khi DB thay schema mới android có thể biết chuyển dât cũ sang table mới ntn. (Sources)
-
Lifecycle
Problem
- Losing data when rotate or move app to background
Fragment
- Get destroyed and rebuilt on rotation
- Get destroyed when back to previous page
Activity
- Get destroyed and rebuilt on rotation
- Get destroyed when back to previous page
-
-
OS
Free up memory by android.
- If the app is on background, and os need more memory -> OS will terminate the app
Reactive Programming1: Explaination of what is reactive programming.
-
-
-
-