anyway, to tell java rx to use the current thread in the observOn function? I am writing code for the syncadapter android and want the results to be observed in the sync adapter thread, and not in the main thread.
An example of a network call with Retrofit + RX Java looks something like this:
MyRetrofitApi.getInstance().getObjects() .subscribeOn(Schedulers.io()) .observeOn(<current_thread>) .subscribe(new Subscriber<Object>() { //do stuff on the sync adapter thread }
I tried to use
... .observeOn(AndroidSchedulers.handlerThread(new Handler(Looper.myLooper()))) ...
similar to how android rx creates a scheduler for the main thread, but it no longer works as soon as I submenu Looper.myLooper() for Looper.getMainLooper() .
I could use Schedulers.newThread (), but as a complex synchronization code with a lot of server calls, I would constantly create a new thread to start new network calls, which again create new threads to start more network calls. Is there any way to do this? Or is my approach completely wrong?
rx-java rx-android android-syncadapter
tiqz
source share