-2

While i'm changing connection, my app crashes and shows the following stacktrace:

E/AndroidRuntime: FATAL EXCEPTION: Timer-3
    Process: com.app.teemchat, PID: 9383
    io.deepstream.DeepstreamException: CONNECTION_ERROR: null
        at io.deepstream.DeepstreamClientAbstract.onError(DeepstreamClientAbstract.java:59)
        at io.deepstream.Connection$1.run(Connection.java:187)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)

Please help me to solve this problem...

client.addConnectionChangeListener(new ConnectionStateListener() {
    @Override
    public void connectionStateChanged(ConnectionState connectionState) throws RuntimeException {
        Log.w(Tag, "ConnectionChange>>> " + connectionState.toString());
        if (connectionState.toString().equalsIgnoreCase(ConnectionState.ERROR.toString())) {
           client.close();
           doLogin();
           }

           if (connectionState.toString().equalsIgnoreCase(ConnectionState.CLOSED.toString())) {
              doLogin();
              }
        }
});
4

1 回答 1

0

AlexBHarley 说需要添加setRuntimeErrorHandler https://github.com/deepstreamIO/deepstream.io-client-java/issues/85

这是预期的连接已经死亡,所以有一个CONNECTION_ERROR。如果您不希望这引发异常,您可以使用 client.setRuntimeErrorHandler 在错误事件上放置一个侦听器。诚然,原因可能比 null 更好。目前的方法是两件事之一,

无限重新连接尝试存储一些本地状态并在互联网连接恢复时重新启动会话。我们希望在不久的将来通过恢复会话等解决一些更好的离线优先功能。

于 2018-09-03T07:41:00.283 回答