Observable observable = Observable.from(backToArray(downloadWebPage("URL")))
.map(new Func1<String[], Pair<String[], String[]>>() {
@Override
public Pair<String[], String[]> call(String[] of) {
return new Pair<>(of,
backToArray(downloadWebPage("URL" + of[0])).get(0));
}
});
observable.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(
(new Observer<Pair>() {
@Override
public void onCompleted() {
// Update user interface if needed
}
@Override
public void onError(Throwable t) {
// Update user interface to handle error
}
@Override
public void onNext(Pair p) {
offices.add(new Office((String[]) p.first, (String[]) p.second));
}
}));
这运行,我得到 android.os.NetworkOnMainThreadException。我希望它运行 subscribeOn() 方法设置的新线程。