I am trying to learn Rxjava2. I am facing a problem i.e, NetworkOnMainThreadException during network call using okHttp. I have to use only okHttp libary.
This is my meth
just remove Observable.just() as follows
service.getData(httpParamObject)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((Consumer<? super Object>) getObserver());
You're calling service.getData(httpParamObject)
in the main thread and passing that result to Observable.just
. So your subscribeOn
has no effect.
Check the documentation of Observable.create and use it instead of Observable.just