简体   繁体   English

在Android中重新连接Nodejs SocketIO

[英]Reconnect Nodejs SocketIO in android

I'm creating a chat app with nodejs socketIO in android. 我正在使用Android中的nodejs socketIO创建一个聊天应用程序。 I have a problem when i press the back button on the Activity it will return to the login Activity and disconnect the nodejs socketIO and i want to login again but not connected to nodejs socketIO again . 我在按下Activity上的后退按钮时遇到问题,它将返回登录Activity并断开nodejs socketIO的连接,我想再次登录但又不想再次连接到nodejs socketIO。 How to reconnect . 如何重新连接。 Please help me 请帮我

Here is logic which you can apply. 这是您可以应用的逻辑。

  1. You have to store a flag in your android application which will maintenance login status. 您必须在Android应用程序中存储一个标志,该标志将维护登录状态。 once you move from login screen to chat screen, update your flag to true. 从登录屏幕移至聊天屏幕后,将标志更新为true。 so now you know that you have already login and you are in chat screen where you will have socket object. 所以现在您知道您已经登录,并且在聊天屏幕中将有了套接字对象。 please save that socket object. 请保存该套接字对象。
  2. Now when you press the back button then you should know that you have already login by a flag which you have saved so auto redirects the user to chat screen. 现在,当您按下“后退”按钮时,您应该知道您已经通过保存的标志登录,因此自动将用户重定向到聊天屏幕。 as you already have socket.io object, you can do communication same as before. 因为已经有了socket.io对象,所以可以像以前一样进行通信。

I hope this answer helps you and solve your problem. 我希望这个答案可以帮助您并解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM