[英]Hot to track progress with RxAndroid?
I have in my project Retrofit library and RxAndroid. 我的项目Retrofit库和RxAndroid中。
For example I've called some method from my api 例如,我已经从我的api调用了一些方法
public void loadSomething() {
getApi().getSomething()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Something>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Something s) {
}
});
}
How should I track progress of this observable for example to prevent user to start it second time? 我应如何跟踪此可观察对象的进度,例如防止用户第二次启动它? Should add my custom flags something like before start set
inProgress = true;
应该添加我的自定义标志,例如在开始之前设置
inProgress = true;
and in all callback methods set inProgress = false;
并在所有回调方法中设置
inProgress = false;
? ?
Can I do it with RxAndroid functionality? 我可以使用RxAndroid功能吗? Or is it guarantee that one call to api will not be started few times in parallel?
还是保证不会一次并行调用api几次?
You can use the Do operator . 您可以使用Do运算符 。
You can set the inPogress = true
in doOnSubscribe()
and inProgress = false
in doOnComplete()
. 您可以设置
inPogress = true
在doOnSubscribe()
和inProgress = false
在doOnComplete()
Also calling subscribe
returns a Subscription . 也调用
subscribe
返回Subscription 。 You can use it to check if the call has finished using isUnsubscribed()
. 您可以使用
isUnsubscribed()
来检查调用是否完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.