Search code examples
javarx-javareactive-programmingrx-androidreactivex

RxJava ignore onNext


I'm calling a url with Retrofit, and I don't care about the result. Is there anyway to ignore the onNext method?

Currently I'm using:

getRetrofit().create(UserAPI.class)
        .doSomething(a, b)
        .subscribeOn(Schedulers.newThread())
        .subscribe(t -> {}, Handler::handlerError);

As you can see, t -> {} do nothing, and I want to reduce it like:

getRetrofit().create(UserAPI.class)
            .doSomething(a, b)
            .subscribeOn(Schedulers.newThread())
            .subscribe(null, Handler::handlerError);

but get the error

java.lang.IllegalArgumentException: onNext can not be null

Solution

  • Instead of Observable you can return Completable from your Retrofit interface. It serves exactly same purpose you need.