简体   繁体   中英

Reconnect Nodejs SocketIO in android

I'm creating a chat app with nodejs socketIO in android. 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 . 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. once you move from login screen to chat screen, update your flag to 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.

I hope this answer helps you and solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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