Observable<String> test1 = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext("test1");
}
});
Observable<String> test2 = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext("test2");
}
});
Observable.concat(test1, test2)
.toList()
.subscribe(new Action1<List<String>>() {
@Override
public void call(List<String> strings) {
System.out.println(strings);
}
});
最近在工作中使用rxjava時(shí)發(fā)現(xiàn)就上面一段代碼執(zhí)行時(shí)并不會(huì)像期望的那樣打出test1捐寥,test2,后來經(jīng)過研究后發(fā)現(xiàn)在創(chuàng)建Observable時(shí)加上subscriber.onCompleted();就可以了祖驱,不知道為什么會(huì)這樣握恳,這里暫時(shí)記錄一下