【发布时间】:2016-12-14 01:25:01
【问题描述】:
我正在尝试使用改造向 api 发送网络请求,当我得到响应时,在另一个调用中使用该响应的一部分,我按照建议使用了调用和 rxjava,但我总是执行第二个请求在第一个之前
public interface ChannelRequest {
@POST("authenticate_with_options")
@FormUrlEncoded
Observable<Channel> getAuthenticationChannel(@FieldMap Map<String, String> params);
@POST("check")
@FormUrlEncoded
Observable<Channel> getAuthenticationStatus(@FieldMap Map<String, String> params);
}
ss
Observable<Channel> call2 = mAPI.gettheChannel().getAuthenticationStatus(Constants.HTTP.PARAMSAUTH);
Observable.interval(3, TimeUnit.SECONDS).retry(3);
Subscription subscription2 = call2
.subscribeOn(Schedulers.io()) // optional if you do not wish to override the default behavior
.observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Channel>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
if (e instanceof HttpException) {
HttpException response = (HttpException) e;
int code = response.code();
}
}
@Override
public void onNext(Channel channel) {
Log.d("AuthStatus", "onResponse: " + Channel.getChannel());
}
});
我不确定我是否必须再使用 RxJava,实现这一目标的最佳实践是什么?
谢谢
【问题讨论】:
标签: android rx-java retrofit2 rx-android okhttp3