Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
RxLifecycle
https://github.com/zhihu/rxlifecycle
Admin
Bind observables to the lifecycle of Activity or Fragment in a non-invasive way.
Tokens:
295
Snippets:
3
Trust Score:
8.2
Update:
1 year ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Add JitPack Repository to Gradle Source: https://github.com/zhihu/rxlifecycle/blob/master/README.md This snippet shows how to add the JitPack Maven repository to your project's `build.gradle` file. Adding this repository is a prerequisite for fetching the RxLifecycle library dependencies. ```gradle repositories { maven { url "https://jitpack.io" } } ``` -------------------------------- ### Add RxLifecycle Library Dependencies Source: https://github.com/zhihu/rxlifecycle/blob/master/README.md Illustrates how to declare the RxLifecycle library and its optional compact version as dependencies in your `build.gradle` file. Replace `{lastest-version}` with the actual latest version of the library to integrate it into your Android project. ```gradle dependencies { compile 'com.github.nekocode.rxlifecycle:rxlifecycle:{lastest-version}' compile 'com.github.nekocode.rxlifecycle:rxlifecycle-compact:{lastest-version}' // Optional } ``` -------------------------------- ### Unsubscribe RxJava Observable with RxLifecycle Source: https://github.com/zhihu/rxlifecycle/blob/master/README.md Demonstrates the simplest way to use RxLifecycle to automatically dispose an RxJava observable sequence. By composing with `RxLifecycle.bind(this).disposeObservableWhen(LifecycleEvent.DESTROY_VIEW)`, the observable will be unsubscribed when the specified lifecycle event occurs, preventing further emissions. ```java Observable.interval(0, 2, TimeUnit.SECONDS) // ... .compose(RxLifecycle.bind(this) .<Long>disposeObservableWhen(LifecycleEvent.DESTROY_VIEW)) .subscribe(); ```