RxLifecycle

General

Category
Free
Tag
FRP
License
MIT License
Min SDK
19 (Android 4.4 KitKat)
Registered
Aug 6, 2017
Favorites
2
Link
https://github.com/mahmed8003/RxLifecycle
See also
Rx2Groups
RxActions
RxSealedUnions
rxjava-extras
RxTry

Additional

Language
Java
Version
N/A
Created
Jul 29, 2017
Updated
Aug 16, 2017 (Retired)
Owner
Muhammad Ahmed (mahmed8003)
Contributor
Muhammad Ahmed (mahmed8003)
1
Activity
Badge
Generate
Download
Source code

Advertisement

RxLifecycle

This library handles disposing of Observer on different lifecycle events.

Usage

Extend Activity from RxActivity

public class MainActivity extends RxActivity {

or Fragment from RxFragment

public class MainFragment extends RxFragment {

Create a Disposable

Disposable d = Observable
                .interval(1, TimeUnit.SECONDS)
                .subscribeWith(new DisposableObserver<Long>() {
                    @Override
                    public void onNext(Long value) {
                        Log.d(TAG, value.toString() + " Seconds");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e(TAG, "onError", e);
                    }

                    @Override
                    public void onComplete() {
                        Log.d(TAG, "onComplete");
                    }
                });

Now if you want to dispose Disposable "d" on a specific event - e.g., onResume

this.dispose(d, ActivityEvent.RESUME);

or if you want to dispose Disposable "d" on a opposing lifecycle event - e.g., if subscribing during START, it will terminate on STOP

this.dispose(d);

Installation

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

and:

dependencies {
    compile 'com.github.mahmed8003:RxLifecycle:0.0.4'
}