BlockingGet block UI thread RxJava 2

后端 未结 3 2037
[愿得一人]
[愿得一人] 2020-12-20 17:11

I am dealing with the problem.

I am trying to call RxJava in the sync manner, however doing that results in blocking the Main thread.

Here is my code

3条回答
  •  情书的邮戳
    2020-12-20 17:37

    If you really need a function to run on the main thread and also need it to be synchronous, then you could do something like this:

    1. If this is the main thread (Looper.myLooper() == Looper.getMainLooper()), then run func()

    2. If not on the main thread, then you can use the combination of observeOn(AndroidSchedulers.mainThread()) with blockingGet()

提交回复
热议问题