Rxandroid What's the difference between SubscribeOn and ObserveOn

后端 未结 5 2022
逝去的感伤
逝去的感伤 2020-12-23 09:09

I am just learning Rx-java and Rxandroid2 and I am just confused what is the major difference between in SubscribeOn and ObserveOn.

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 09:51

    SubscribeOn specify the Scheduler on which an Observable will operate. ObserveOn specify the Scheduler on which an observer will observe this Observable.

    So basically SubscribeOn is mostly subscribed (executed) on a background thread ( you do not want to block the UI thread while waiting for the observable) and also in ObserveOn you want to observe the result on a main thread...

    If you are familiar with AsyncTask then SubscribeOn is similar to doInBackground method and ObserveOn to onPostExecute...

提交回复
热议问题