我试图根据响应中的某些逻辑重定向到两个不同的活动。但是每次我请求时都会遇到致命异常:
java.lang.IllegalStateException:调度程序上引发了致命异常。
我的代码:
this.responseConnectionObservable = apiService.getConnections(token);
this.responseConnectionObservable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ConnectionsResponse>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(ConnectionsResponse connectionsResponse) {
if (connectionsResponse.getSuccess()) {
Log.d("body", "post submitted to API.");
connectionsResponseParent = connectionsResponse;
store.put("token", connectionsResponse.getSecurityResponse().getToken());
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
if (!connectionsResponseParent.getPayload().getPersonList().isEmpty() || !connectionsResponseParent.getPayload().getCompanyList().isEmpty()) {
for (PartyListResponse party : connectionsResponseParent.getPayload().getPersonList()) {
accounts.add(new Account(party.getId(), party.getUrl(), party.getName(), party.getShareType()));
}
for (PartyListResponse party : connectionsResponseParent.getPayload().getCompanyList()) {
accounts.add(new Account(party.getId(), party.getUrl(), party.getName(), party.getShareType()));
}
Intent intent = new Intent(getApplicationContext(), SwitchAccountActivity.class);
intent.putExtra("mDataSet", accounts);
startActivity(intent);
finish();
} else {
Intent intent = new Intent(getApplicationContext(), CreateEntityActivity.class);
startActivity(intent);
finish();
}
}
});
我在做什么错?我是RX的新手,在这种情况下,不要在线程之间切换。