這個插件讓你可以使用你選擇的調度器覆蓋默認的計算、IO和新線程調度 (Scheduler),要做到這些,需要繼承 RxJavaSchedulersHook 類并覆寫這些方法:
Scheduler getComputationScheduler(?)Scheduler getIOScheduler(?)Scheduler getNewThreadScheduler(?)Action0 onSchedule(action)然后是下面這些步驟:
RxJavaSchedulersHook 子類的對象。RxJavaPlugins.getInstance(?) 獲取全局的RxJavaPlugins對象。RxJavaPlugins 的 registerSchedulersHook(?) 方法。完成這些后,RxJava會開始使用你的方法返回的調度器,而不是內置的默認調度器。
這個插件讓你可以注冊一個函數處理傳遞給 Subscriber.onError(Throwable) 的錯誤。要做到這一點,需要繼承 RxJavaErrorHandler 類并覆寫這個方法:
void handleError(Throwable e)然后是下面這些步驟:
RxJavaErrorHandler 子類的對象。RxJavaPlugins.getInstance(?) 獲取全局的RxJavaPlugins對象。RxJavaPlugins 的 registerErrorHandler(?) 方法。完成這些后,RxJava會開始使用你的錯誤處理器處理傳遞給 Subscriber.onError(Throwable) 的錯誤。
這個插件讓你可以注冊一個函數用于記錄日志或者性能數據收集,RxJava在某些常規(guī)活動時會調用它。要做到這一點,需要繼承 RxJavaObservableExecutionHook 類并覆寫這些方法:
| 方法 | 何時調用 |
|---|---|
| onCreate(?) | 在 Observable.create(?)方法中 |
| onSubscribeStart(?) | 在 Observable.subscribe(?)之前立刻 |
| onSubscribeReturn(?) | 在 Observable.subscribe(?)之后立刻 |
| onSubscribeError(?) | 在Observable.subscribe(?)執(zhí)行失敗時 |
| onLift(?) | 在Observable.lift(?)方法中 |
然后是下面這些步驟:
RxJavaObservableExecutionHook 子類的對象。RxJavaPlugins.getInstance(?) 獲取全局的RxJavaPlugins對象。RxJavaPlugins 的 registerObservableExecutionHook(?) 方法。When you do this, RxJava will begin to call your functions when it encounters the specific conditions they were designed to take note of. 完成這些后,在滿足某些特殊的條件時,RxJava會開始調用你的方法。