Android Architecture Components

2018. 4. 10. 22:32Work/Android

728x90
반응형

Android Architecture Components

  • Life-cycle with ease(라이프 사이클의 용이)

 A. Live Data

ㅇ 관찰자 데이터 홀더 클래스 (Observable data holder class)
- 라이프 사이클 인식, Fragment 또는 Service 같은 다른 앱 구성 요소 주기를 존중
  (lifecycle-aware, it respects the lifecycle of other app components, such as activities, fragments, or services)

 UI가 데이터 상태와 일치하는지 확인 (UI matches your data state)
관찰자 패턴에 따릅니다.
  (follows observer pattern) 

 메모리 누출 없음 (No memory leaks)
- Lifecycle객체에 묶여있고 연관된 라이프 사이클이 파괴되면 스스로 정리
  (bound to lifecycle objects and clean up after themselves when their associated lifecycle is destroyed) 

 활동이 중지 되어도 충돌 없음 (No crashes due to stopped activities)
관찰자의 라이프 사이클이 백스택의 활동과 같이 비활성인 경우 이벤트를 수신하지 않음
  (If the observer's lifecycle is inactive, such as in the case of an activity in the back stack, then it doesn't receive any LiveData events) 

 라이프 사이클 처리에 대한 더 이상의 처리가 없음 (No more manual lifecycle handling)
UI 구성 요소는 관련 데이터를 관찰하고 관찰을 중지하거나 다시 시작하지 않음, 자동으로 관리
  (UI components just observe relevant data and don't stop or resume observation. automatically manages all of this since it's aware of the relevant lifecycle status changes) 

 항상 최신 데이터 (Always up to date data)
라이프 사이클이 비활성 상태에서 다시 활성화하면 최신 데이터를 수신, 백그라운드에 있던 활동은 포그라운드로 돌아온 직후에 최신 데이터를 받습니다.
  (If a lifecycle becomes inactive, it receives the latest data upon becoming active again. activity that was in the background receives the latest data right after it returns to the foreground) 

 적절한 구성 변경 (Proper configuration changes)
구성 변경으로 인해 Activity 또는 Fragment가 다시 작성되면 즉시 사용 가능한 최신 데이터 수신
  (If an activity or fragment is recreated due to a configuration change, like device rotation, it immediately receives the latest available data) 

 리소스 공유 (Sharing resources)
- 싱글톤 패턴을 사용하여 객체를 확장, 시스템 서비스를 래핑하여 응용프로그램에서 공유할 수 있습니다.
  (using singleton pattern to wrap system services so that they can be shared in your app.) 

B. ViewModel

    ㅇ UI 관련 데이터를 라이프 사이클을 고려한 방식으로 저장, 관리하도록 설계 (designed to store and manage UI-related data in a lifecycle conscious way)

    ㅇ ViewModel의 라이프 사이클 (The lifecycle of a ViewModel)

ㅇ ViewModel의 데이터로드 (로더 대체)

- 로더 클래스 01)CursorLoader는 데이터베이스와 동기화되어 앱의 UI에 데이터를 보관하는데 자주 사용됩니다. 이를 ViewModel로 대체하기 위해 Room 및 LiveData와 함께 작동합니다. Room은 LiveData 데이터베이스가 변경된 시점을 알려주고, LiveData는 수정된 데이터로 UI를 업데이트 합니다.

  (Loader classes like CursorLoader are frequently used to keep the data in an app's UI in sync with a database. viewModel works with Room and LiveData to replace the loader. The ViewModel ensures that the data survives a device configuration change. Room informs your LiveData when the database changes, and the LiveData, in turn, updates your UI with the revised data) 






C. LifecycleObserver

D. LifecycleOwner

    ㅇ 단일 메소드 인터페이스, 라이프 사이클이 있는 클래스 (Single method interface)

  • Room 

 SQLite 객체 매핑 라이브러리

ㅇ SQLite 테이블 데이터를 Java 객체로 쉽게 변환, RxJava, Flowable 및 LiveData 관찰을 반환할 수 있습니다. 
    (avoid boilerplate code and easily convert SQLite table data to java objects using Room. Room provides compile time checks of SQLite statemnets and can return RxJava, Flowable and LiveData observables)

ㅇ SQLite를 통해 추상화 계층 제공
    (The Room persistence library provides an abstraction layer over SQLite to allow fluent DB access while harnessing the full power of SQLite)

  • Paging 

 필요에 따른 데이터 로드

ㅇ 데이터 소스에서 필요한 만큼 정보를 점차적으로 로드 할 수 있습니다. (without overloading the device or waiting too long for a big database query)

| 출처

 Android Architecture Components : https://developer.android.com/topic/libraries/architecture/index.html

 LiveData : https://developer.android.com/topic/libraries/architecture/livedata.html

 ViewModel : https://developer.android.com/topic/libraries/architecture/viewmodel.html

 Room : https://developer.android.com/topic/libraries/architecture/room.html

 Paging : https://developer.android.com/topic/libraries/architecture/paging.html


| Deep 

 01) 링크, CursorLoader : Loader커서를 문의하기 위한 표준적인 방법으로 프로토콜 구현, AsyncTaskLoader 백그라운드의 thread로 커서 쿼리를 실행해, 어플리케이션의 UI를 블록하지 않게 합니다.

728x90
반응형

'Work > Android' 카테고리의 다른 글

Android P  (0) 2018.03.19
Android 저장소 옵션(Repository Option)  (0) 2018.01.30
Android 앱 구성 요소(Component)  (0) 2018.01.29
Android Async  (0) 2018.01.17
Android ART & DVM & JVM  (0) 2018.01.12