2017/5/18 Google IO
Android Architecture Components: 一個新的庫集合,幫助您設(shè)計(jì)健壯的、可測試的和可維護(hù)的應(yīng)用程序。從管理UI組件生命周期和處理數(shù)據(jù)持久性開始。
將組件添加到項(xiàng)目
- 在項(xiàng)目的 build.gradle添加
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
- 在module中使用
//For Lifecycles, LiveData, and ViewModel, add:
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
//For Room, add:
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
輕松管理應(yīng)用程序的生命周期
新的生命周期感知組件幫助你管理activity和fragment的生命周期。配置信息變化之后,避免內(nèi)存泄漏,很容易將數(shù)據(jù)通過使用livedata,ViewModel,lifecycleobserver和LifecycleOwner加載到UI。
Room: ORM 組件
Room:一個SQLite對象映射庫,避免樣板代碼,使用Room輕松地將SQLite表中的數(shù)據(jù)轉(zhuǎn)化為java對象。Room提供編譯時檢查SQLite語句,可以返回RxJava, Flowable and LiveData observables。
詳細(xì)使用方式 Room ORM 數(shù)據(jù)庫框架