bryant1410
bryant1410

Reputation: 6380

NetworkOnMainThreadException with retrofit-beta2 and rxjava

I recently upgraded from retroft-beta1 and this was working. I have the following interface for the API:

public interface Service {
    @POST("path")
    Observable<Object> service();
}

And the following call:

service.service()
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe();

And it throws a NetworkOnMainThreadException. But this was working in retrofit-beta1.

Upvotes: 3

Views: 858

Answers (1)

bryant1410
bryant1410

Reputation: 6380

From retrofit-beta2, calls to Observable methods now behave synchronously. So subscribeOn must be used:

service.service()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe();

Upvotes: 8

Related Questions