rxJava中 Subscriber 与Observer
Subscriber 与Observer 两者关系
1、 Subscriber是Observer接口的一个抽象实现;
2、subscribe这种订阅方式在第二次请求数据时就不会执行了;
3、Observer 订阅方式可以无限次数执行;
4、subscribe 订阅方式在onCompleted后自动取消了订阅 ;
5、Observer 订阅方式没有自动取消订阅,不能取消订阅;
subscribe(new Subscriber< T>() {})方式实现订阅,也可以达到无限次数的订阅 private void toSubscribe(Observable<Response<D>> observable) { observable.subscribeOn(Schedulers.io()) .map(new Func1<Response<D>,D>() { @Override public D call(Response<D> response) { if(response == null){ throw new ApiException(100); } totalPage = response.total; return response.result; } }) .observeOn(AndroidSchedulers.mainThread()) //重点在这 .subscribe(new Subscriber<D>() { @Override public void onCompleted() { executeOnLoadFinish(); } @Override public void onError(Throwable e) { TLog.error("onError " + e.toString()); executeOnLoadDataError(null); } @Override public void onNext(D d) { TLog.log("onNext " ); List<T> list = d; TLog.log("entity " + list.size()); executeOnLoadDataSuccess(list); TLog.log("onSuccess totalPage " + totalPage); } }); }