Search code examples
androidrx-javaretrofit2rx-java2rx-android

RxJava 2 Adapter facory


what is the difference between RxJava2CallAdapterFactory.create() & RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())? Which one should prefer?


Solution

  • Difference from the source code

    Both methods returns an instance of synchronous observable, but the create() method has no schedulers to operate on by default and the createWithSchedulers(Scheduler scheduler) as name suggests, operates on the respective scheduler by default which you mention in method, as per your example it will be Scheduler.io().

    Which one you should use?

    Now this will depend on you, the APIs you directly want to return instance in Schedulers.io() or other Schedulers by default then you use the one with schedulers, else you can use the create() method and can declare schedulers while getting response every time.

    Note: I personally use create() method as I sometimes mention some other Schedulers.newThread() and/or Schedulers.computation()