我尝试从服务器获取一些数据。
Observable<List<Countries>> backendObservable = mCountriesApi.getCountries()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
backendObservable.doOnNext(list -> Log.d(TAG, "doOnNext"));
backendObservable.doAfterNext(list -> Log.d(TAG, "doAfterNext"));
backendObservable.doOnComplete(() -> Log.d(TAG, "doOnComplete"));
backendObservable.subscribe(new Observer<List<Country>>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(List<Country> value) {
Log.d(TAG, "doOnNext"));
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
它起作用,我将数据接收到&#34; onNext&#34;。但方法doOnNext,doAfterNext,doOnComplete不会调用。 我做错了什么?
答案 0 :(得分:0)
你明白了int ret = fseek(stream, -step, SEEK_END);
,发生了什么?您必须在observeOn
上链接运算符,因为它们是不可变的数据流计划:
Observable
或更简洁
backendObservable = backendObservable.doOnNext(list -> Log.d(TAG, "doOnNext"));
backendObservable = backendObservable.doAfterNext(list -> Log.d(TAG, "doAfterNext"));
backendObservable = backendObservable.doOnComplete(() -> Log.d(TAG, "doOnComplete"));