MVP模型RxJava CompositeDisposable我在哪里清除?

时间:2017-04-13 13:42:54

标签: android rx-java mvp rx-android

我使用http://www.tinmegali.com/en/model-view-presenter-mvp-in-android-part-2/的MVP 我在MainModel.java中使用RxJava CompositeDisposable - Observable 我在哪里清除MainModel.java中的CompositeDisposable? 我可以在DisposableObserver的方法onComplete中清除CompositeDisposable吗?

private CompositeDisposable disposables = new CompositeDisposable();

getObservableNote(note)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(d);

    disposables.add(d);

....
..

private Observable<Note> getObservableNote(Note noteadd) {
    return Observable.just(true).map(aBoolean -> {
        Note noteget = doLongOperationNote(noteadd);
        return noteget;
    });
}

private DisposableObserver<Note> getDisposableObserverNote() {
    return new DisposableObserver<Note>() {

        @Override
        public void onComplete() {

            Log.d("Thread onComplete", Thread.currentThread().getName());
            disposables.clear();
        }

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

        @Override
        public void onNext(Note noteget) {
            Log.d("Thread onNext", Thread.currentThread().getName());
            mPresenter.onNoteInsertedNote(noteget);

        }
    };
}

0 个答案:

没有答案