パルカワ2

最近はFlutterをやっています

RxLifeCycle試してる

Single.just(10)
    .doOnDispose(() -> Log.i("TEST", "dispose"))
    compose(bindUntilEvent(ActivityEvent.CREATE))
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(
        i -> Log.i("TEST", String.valueOf(i)),
        throwable -> Log.i("TEST", throwable.toString()));

Single と Completable のときは、 onErrorにCancellationExceptionがくる。

Observable.interval(1, TimeUnit.SECONDS)
    .doOnDispose(() -> Log.i("TEST", "dispose"))
    .compose(bindUntilEvent(ActivityEvent.CREATE))
    .observeOn(AndroidSchedulers.mainThread())
    .doOnComplete(() -> Log.i("TEST", "onComplete"))
    .subscribe(
        i -> Log.i("TEST", String.valueOf(i)),
        throwable -> Log.i("TEST", throwable.toString()),
        () -> Log.i("TEST", "onComplete"));

ObservableとFlowableとMaybeは、onComplete()が実行されるとのこと。

Unsubscription RxLifecycle does not actually unsubscribe the sequence. Instead it terminates the sequence. The way in which it does so varies based on the type: Observable, Flowable and Maybe - emits onCompleted() Single and Completable - emits onError(CancellationException) If a sequence requires the Subscription.unsubscribe() behavior, then it is suggested that you manually handle the Subscription yourself and call unsubscribe() when appropriate.

RxLifeCycleのREADME

実際の処理はPresenterがやるので、bindUntilEvent(ActivityEvent.CREATE) をPresenterに渡す必要があるけど、どうPresenterに渡すのか?? あたりがこれだ!というのが自分の中にない。