-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用的RxLifecycle来管理,但部分机型,长时间锁屏后,再次打开无法连接 #17
Comments
@njzhangsan2013 你的需求应该是要保证在锁屏下保证WebSocket不断连。现在问题应该看你WebSocket在什么时候创建的,以及在长时间锁屏后,是否是系统杀进程了。部分机型出现这种问题,应该是系统内存回收导致的吧,你从这块入手看看,保活处理。或者你试试将这个WebSocket写在service里。然后用rxbus或者eventBus广播试试。 |
在锁屏断开没有问题,重要的是屏幕再次打开时,能重新自动连接上,这个很重要! |
@Override
protected void onResume() {
super.onResume();
RxWebSocketUtil.getInstance().getWebSocketInfo("ws://")
.compose(RxLifecycle.with(this).<WebSocketInfo>bindToLifecycle())
.subscribe(new WebSocketSubscriber() {
@Override
public void onOpen(@NonNull WebSocket webSocket) {
}
@Override
public void onMessage(@NonNull String text) {
}
@Override
public void onMessage(@NonNull ByteString bytes) {
}
});
} 如上,如果在锁屏状态不需要连接WebSocket,在onResume是注册WebSocket,用bindToLifecycle()管理生命周期。你在试一下。 @njzhangsan2013 |
试试以上方法,看看是否能解决问题,给我回复一下。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
用的这种方法,请问如何判断当前websocket是否连接正常,如果不正常怎么办,是否重新创建 RxWebSocketUtil.getInstance().getWebSocketInfo(Constant.SOCKET_URL)
.compose(RxLifecycle.with(this).bindOnDestroy())
.subscribe(new WebSocketSubscriber()
The text was updated successfully, but these errors were encountered: