安卓架构组件Lifecycle的Rx绑定 – RxComponentLifecycle

RxComponentLifecycle

Rx binding of new Android Architecture Component Lifecycle

def arch_version = "1.0.0-alpha1"

dependencies {
    compile 'com.github.florent37:rxcomponent-lifecycle:1.0.0'

    annotationProcessor "android.arch.lifecycle:compiler:$arch_version"
    compile "android.arch.lifecycle:runtime:$arch_version"
    compile "android.arch.lifecycle:extensions:$arch_version"
    
    compile 'io.reactivex.rxjava2:rxjava:2.1.0'
}

Don’t forget to add google’s maven

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

Usage

RxLifecycle.with(getLifecycle())

           .onDestroy() //receive all events
           
           .subscribe(event -> //do what you had to do on view destroy);

Events

RxLifecycle.with(getLifecycle())

           .onCreate() 
           .onStart() 
           .onResume() 
           
           .onPause() 
           .onStop() 
           .onDestroy()
            
           .onEvent() //all events
           
           .subscribe(event -> //do what you had to do on view destroy);

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:安卓架构组件Lifecycle的Rx绑定 – RxComponentLifecycle