为什么#onComplete()呼吁,即使#addSomething()被调用一次两次? 这个代码片段:
private void addSomething() {
Subscriber<AddCommentResponse> subscriber = createSubscriber();
NetworkService.getIp()
.subscribeOn(Schedulers.io())
.flatMap(addSomethingService)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
}
private Subscriber<AddCommentResponse> createSubscriber() {
return new Subscriber<AddCommentResponse>() {
@Override
public void onCompleted() {
this.unsubscribe();
Toast.makeText(
MyApplication.context, getString(R.string.toast_comment_added_successfully), Toast.LENGTH_LONG
).show();
navigateBack();
}
@Override
public void onNext(AddCommentResponse response) {
onCompleted();
}
};