如何在RxJava2中取消订阅observable或subscription?或者我真的需要吗?

时间:2017-08-11 08:58:08

标签: android rx-android rx-java2

如何在RxJava2中取消订阅observable或订阅?或者我真的需要吗?

//Initialising Obersvable         
    Observable<SearchSuggestions> observable = NetworkContext.api.getSearch("");
        //subscribing obersvable on another thread and observing on main thread

            observable.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<SearchSuggestions>() {
                        @Override
                        public void accept(SearchSuggestions searchSuggestions) throws Exception {
    // here I receive the fetched results

                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {
    //here the error
                        }
                    });

0 个答案:

没有答案