如何从android中的观察者的onComplete制作一个意图?

问题描述 投票:0回答:1

我试图根据响应中的一些逻辑重定向到两个不同的活动。但每次我要求我得到致命的例外:

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的新手,如果是这种情况,我不知道如何在线程之间切换。

android rx-android
1个回答
0
投票

好吧,告诉什么是错误有点困难,因为当请求是在不适当的状态下引发时会抛出此异常。告诉它更多细节

© www.soinside.com 2019 - 2024. All rights reserved.