先看一个简单的例子:
//标记为Observable1 Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<? super String> subscriber) { subscriber.onNext("hello world!"); subscriber.onCompleted(); } }) .subscribeOn(Schedulers.newThread()) //Subscriber标记为Subscriber1 .subscribe(new Subscriber<String>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(String s) { } });
subscribeOn的流程如下:
Observable<Observable<String>>
我们命名为Observable2subscribe()过程跟之前分析的的一样。 注意:
Observable<Observable<String>>2
中onSubscribe中的call()方法,返回的是Observable1Observable<Observable<String>>2
发射的Observable1跟Subsriber1关联调用现在分析OperatorSubscribeOn生成的Subscriber2
Subscriber<String>
调用了Subscriber1<String>
中的onNext() onCompleted()等。完毕
原文:http://www.cnblogs.com/liulipeng/p/5126442.html