我是用在改造和Rx的Java 1這個代碼從改造這樣調用返回一個可觀察:改造2 RxJaxa 1可觀察:如何轉換到RxJava 2
mCompositeSubscription.add(
ServiceFactory.createRetrofitService().setLike(mediaId,sessionMgr.getAuthToken())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ResponseBody>() {
@Override
public final void onCompleted() {}
@Override
public final void onError(Throwable e) {
userMessageHandler.showDialog(mParentActivity,mParentActivity.getString(R.string.error_setting_data_title),
mParentActivity.getString(R.string.error_set_like_msg) + e.getMessage(),0);
}
@Override
public void onNext(ResponseBody response) { }
})
);
我想不通如何將其轉換爲Java的RX 2.我想出了這一點,但不知道這是正確的:
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableObserver<User>(){
@Override
public void onNext(User user) {
authMgr.setUser(user);
}
@Override
public void onError(Throwable t) {
mProgressDlg.dismiss();
alertDlg.showIt(mResources.getString(R.string.err_register),
t.getMessage(), "",
"", mParentActivity, JAlertDialog.POSITIVE,null);
}
@Override
public void onComplete() { }
});