Rx java 混合和匹配RxJava订阅线程

Rx java 混合和匹配RxJava订阅线程,rx-java,rx-android,Rx Java,Rx Android,是否可以在RxJava中混合和匹配调度程序线程。基本上,我想在Android上做如下的事情 uiObservable .switchMap(o -> return anotherUIObservable) .subscribeOn(AndroidSchedulers.mainThread()) .switchMap(o -> return networkObservable) .subscribeOn(Schedulers.newThread())

是否可以在RxJava中混合和匹配调度程序线程。基本上,我想在Android上做如下的事情

uiObservable
    .switchMap(o -> return anotherUIObservable)
    .subscribeOn(AndroidSchedulers.mainThread())
    .switchMap(o -> return networkObservable)
    .subscribeOn(Schedulers.newThread())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(result -> doSomething(result))

这在同一订阅中可能吗?

是的,在您完全理解逻辑之后,这是可能的,而且非常简单。但您可能会混淆observeOn()和subscribeOn()运算符:)

也许这就是你想要的:

uiObservable
    .switchMap(o -> return anotherUIObservable)
    .subscribeOn(AndroidSchedulers.mainThread()) // run the above on the main thread

    .observeOn(Schedulers.newThread())
    .switchMap(o -> return networkObservable) // run this on a new thread

    .observeOn(AndroidSchedulers.mainThread()) // run the subscribe on the mainThread
    .subscribe(result -> doSomething(result))

奖励:我写过关于这些操作符的文章,希望它能帮助你

是的,在你完全理解了逻辑之后,这是可能的,而且非常简单。但您可能会混淆observeOn()和subscribeOn()运算符:)

也许这就是你想要的:

uiObservable
    .switchMap(o -> return anotherUIObservable)
    .subscribeOn(AndroidSchedulers.mainThread()) // run the above on the main thread

    .observeOn(Schedulers.newThread())
    .switchMap(o -> return networkObservable) // run this on a new thread

    .observeOn(AndroidSchedulers.mainThread()) // run the subscribe on the mainThread
    .subscribe(result -> doSomething(result))

奖励:我写过关于这些操作符的文章,希望它能帮助你

是的,在你完全理解了逻辑之后,这是可能的,而且非常简单。但您可能会混淆observeOn()和subscribeOn()运算符:)

也许这就是你想要的:

uiObservable
    .switchMap(o -> return anotherUIObservable)
    .subscribeOn(AndroidSchedulers.mainThread()) // run the above on the main thread

    .observeOn(Schedulers.newThread())
    .switchMap(o -> return networkObservable) // run this on a new thread

    .observeOn(AndroidSchedulers.mainThread()) // run the subscribe on the mainThread
    .subscribe(result -> doSomething(result))

奖励:我写过关于这些操作符的文章,希望它能帮助你

是的,在你完全理解了逻辑之后,这是可能的,而且非常简单。但您可能会混淆observeOn()和subscribeOn()运算符:)

也许这就是你想要的:

uiObservable
    .switchMap(o -> return anotherUIObservable)
    .subscribeOn(AndroidSchedulers.mainThread()) // run the above on the main thread

    .observeOn(Schedulers.newThread())
    .switchMap(o -> return networkObservable) // run this on a new thread

    .observeOn(AndroidSchedulers.mainThread()) // run the subscribe on the mainThread
    .subscribe(result -> doSomething(result))

奖金:我已经写了关于这些运营商的文章,希望能有所帮助

谢谢!!我现在有一大堆后续问题,我会在有时间的时候提出。@SaadFarooq请随意提问:)谢谢!!我现在有一大堆后续问题,我会在有时间的时候提出。@SaadFarooq请随意提问:)谢谢!!我现在有一大堆后续问题,我会在有时间的时候提出。@SaadFarooq请随意提问:)谢谢!!我现在有一大堆后续问题,我会在有时间的时候提出。@SaadFarooq请随意提问:)