2017/5/18 Google IO
Android Architecture Components: 一個(gè)新的庫(kù)集合,幫助您設(shè)計(jì)健壯的老充、可測(cè)試的和可維護(hù)的應(yīng)用程序葡盗。從管理UI組件生命周期和處理數(shù)據(jù)持久性開(kāi)始。
將組件添加到項(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ù)通過(guò)使用livedata,ViewModel喘先,lifecycleobserver和LifecycleOwner加載到UI钳吟。
Room: ORM 組件
Room:一個(gè)SQLite對(duì)象映射庫(kù),避免樣板代碼窘拯,使用Room輕松地將SQLite表中的數(shù)據(jù)轉(zhuǎn)化為java對(duì)象红且。Room提供編譯時(shí)檢查SQLite語(yǔ)句,可以返回RxJava, Flowable and LiveData observables。
詳細(xì)使用方式 Room ORM 數(shù)據(jù)庫(kù)框架