NetworkOnMainThreadException using OkHttp with RxJava2

后端 未结 2 1767
情话喂你
情话喂你 2021-01-29 08:28

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

相关标签:
2条回答
  • 2021-01-29 09:05

    just remove Observable.just() as follows

      service.getData(httpParamObject)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe((Consumer<? super Object>) getObserver());
    
    0 讨论(0)
  • 2021-01-29 09:11

    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

    0 讨论(0)
提交回复
热议问题