An rxjava implementation of Livedata for Lifecycle cache and use Active or unActive
Using JCenter:
repositories {
jcenter()
}
dependencies {
compile 'cn.xiaoman.library.android:rxandroidlive:1.0.0'
}
RxJava 2.1.0+ AndroidX Lifecycle 2.1.0+
Just enable RxService as soon as possible. In Android, for example:
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Flowable.interval(1, TimeUnit.SECONDS)
.compose(RxAndroidLive.<Long>bindLifecycle(this, true, AndroidSchedulers.mainThread()))
.subscribe(new Subscriber<Long>() {
@Override
public void onSubscribe(Subscription s) {
addContent("Flowable onSubscribe");
final int requestNum = 10;
s.request(requestNum);
addContent("Flowable request " + requestNum);
}
@Override
public void onNext(Long aLong) {
addContent("Flowable onNext value " + aLong);
}
@Override
public void onError(Throwable t) {
addContent("Flowable onError");
}
@Override
public void onComplete() {
addContent("Flowable onComplete");
}
});
}
}