3

I'm using RxJava2 Android Networking for network call. The problem I'm facing is when I'm trying to hit the API through Schedulers.io() sometimes it does not give any response whereas when I tried hitting the API with Schedulers.newThread() it always gives a response

.subscribeOn(Schedulers.newThread()) AND .subscribeOn(Schedulers.io())

Abhishek Jain
  • 3,562
  • 2
  • 26
  • 44
Harmeet Kaur
  • 154
  • 14
  • 2
    [this](https://stackoverflow.com/q/33415881/3857465) and [this](https://stackoverflow.com/q/31276164/3857465) might be helpful – Abhishek Jain Apr 26 '18 at 06:57
  • Please provide some code to show what your flow looks like. In general, both scheduler types should work. – akarnokd Apr 26 '18 at 07:39

1 Answers1

0

I think there are a lot of reasons if you didn't receive a response from the beck-end server.

Bellow i will post-you some example code for making network-call via rxJava2. Note that the job is executed via Schedulers.io() and result is observerd on the main-thread. Note that getCoinList() should return some observable

service.getCoinList()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Observer<CoinList>() {
        @Override
        public void onSubscribe(Disposable d) {

        }

        @Override
        public void onNext(CoinList coinList) {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onComplete() {

        }
   });
Kostadin Georgiev
  • 866
  • 1
  • 9
  • 23