Bind observables to the lifecycle of Activity or Fragment in a non-invasive way.
Java
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
gradle/wrapper
rxlifecycle-compact Use custom operator to dispose the stream Jan 4, 2018
rxlifecycle
.gitignore
README.md Update README.md Jan 29, 2018
build.gradle Use custom operator to dispose the stream Jan 4, 2018
gradle.properties Use custom operator to dispose the stream Jan 4, 2018
gradlew Initial commit Jan 21, 2017
gradlew.bat
settings.gradle

README.md

RxLifecyle is a library that can help you to unsubscribe the observable sequences automatically when a activity or fragment is destroying. There are some differences between this library and trello/RxLifecycle:

  • This library will actually unsubscribe the sequence (See here). It means that the downstream observer will not receive onComplete(), onError()... anymore when the unsubscription occurs.

  • This library doesn't require you to inherit any activity or fragment. It will insert a non-gui fragment to your activity or fragment to listen the lifecycle events.

The simplest usage:

Observable.interval(0, 2, TimeUnit.SECONDS)
        // ...
        .compose(RxLifecycle.bind(this)
                .<Long>disposeObservableWhen(LifecycleEvent.DESTROY_VIEW))
        .subscribe();

In order to make sure the downstream will not continue to emit items, you need to put the compose(RxLifecycle.bind ..) at the bottom of the chain call. See the example for learning more usages.

To integrate this library to your project, you need to add the JitPack repository to build.gradle repositories firstly.

repositories {
    maven { url "https://jitpack.io" }
}

And then add library dependencies:

dependencies {
    compile 'com.github.nekocode.rxlifecycle:rxlifecycle:{lastest-version}'
    compile 'com.github.nekocode.rxlifecycle:rxlifecycle-compact:{lastest-version}' // Optional
}

This project is licensed under Apache 2.0. The lastest version of the library is Release.