从rxjava1迁移到2

时间:2018-07-09 07:24:44

标签: android rx-java rx-java2

我当前正在使用rxJava1,并且想要迁移到rxjava2。面临着许多问题的迁移,尤其是与进口有关。

这是我的示例代码:-

private void loginCall(final Observable<ResponseLogin> login) {
      {
        try {
            login.
                    subscribeOn(Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<ResponseLogin>() {
                        @Override
                        public void onCompleted() {
                        }

                        @Override
                        public void onError(Throwable e) {
                            mView.showToast("Something Went Wrong. 
Please try again.");
                            mView.signUpFailure(e.getMessage());

mView.loginAnalyticsResponse(e.getMessage());
                        }

                        @Override
                        public void onNext(ResponseLogin response) {
                            try {
                                String jsonResponse = new Gson().toJson(response);
                                mView.loginAnalyticsResponse(jsonResponse);
                            } catch (Exception e) {

                            }

                            if (response != null) {
                                mModel.saveLoginDataInApp(response);
                                Log.d("AAAA",""+response.getData().getProfile().getStage());
                                mView.signUpSuccess(response);
                            } else {
                                mView.showToast("Result is Empty");
                                //mView.signUpFailure(e);
                            }
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

这些是我正在使用的导入:-

import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; 

请帮助我将此代码移至rxjava2

0 个答案:

没有答案