Rxjava: rxjava to rxjava2 Difficulties

Created on 22 Feb 2017  路  4Comments  路  Source: ReactiveX/RxJava

I could not apply it to rxjava2 anyway. Help me. I using before handle my model response this method with rxjava,

void getVehicleListTask(String userName, String userPassword) {

    private Subscription mSubscription;
    mSubscription = mDataManager.vehicleList(userName, userPassword)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.io())
        .subscribe(new Subscriber<GetVehicleList>() {
          @Override
          public void onCompleted() {
          }

          @Override
          public void onError(Throwable e) {
          }

          @Override
          public void onNext(GetVehicleList getVehicleList) {
          }
     });
}
2.x Android Question

All 4 comments

I don't understand your statements. Are you asking about how to turn this into 2.x code?

import io.reactivex.*;
import io.reactivex.schedulers.*;
import io.reactivex.subscribers.*;
import io.reactivex.android.schedulers.*;

// ...

private Disposable mSubscription;

void getVehicleListTask(String userName, String userPassword) {
   Observable<GetVehicleList> source = mDataManager.vehicleList(userName, userPassword);
    mSubscription = source
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.io())
        .subscribeWith(new DisposableObserver<GetVehicleList>() {
          @Override
          public void onComplete() {
          }

          @Override
          public void onError(Throwable e) {
          }

          @Override
          public void onNext(GetVehicleList getVehicleList) {
          }
     });
}

Edit: updated to to use Observable as it wasn't clear from the OP's question.

MyService -> https://gist.github.com/ulaserdegor/4191d7623ff88d896141983684e8b3f4
DataManager -> https://gist.github.com/ulaserdegor/d9356fcb44dd3d5123198d164a5e6eb8
MyPresenter -> https://gist.github.com/ulaserdegor/9540714bfd40e250f53a444746d9fdd1

But still not working.

Unchecked method 'subscribeWith(E)' invocation
subscribeWith
(io.reactivex.Observer & anonymous io.reactivex.subscribers.DisposableSubscriber)
in Observable聽cannot be applied
to
(anonymous io.reactivex.subscribers.DisposableSubscriber)

@akarnokd

See my updated answer above.

@akarnokd thanks!

Was this page helpful?
0 / 5 - 0 ratings