问题
I have a phonegap application which uses socket.io as means of communication. When application goes to pause the socket is kept alive in the background apparently, and on resume when the page loads it replaces the old socket with a new one, and creates a new socket. By each resume socket connections are one more.
Is there a way to keep the old socket connection when application resumes? Or to disconnect it when the application pauses? I'm using phonegap-websocket.
回答1:
I have a similar issue. I also have a websocket-connection, that ought to be brought down when the app is sent to the background and reopened once the app is brought to the foreground again.
According to documentation, I'd use the "pause" event to tear down the communication and then reopen the socket when the "resume" event is received. But this only works as long as "keepRunning" is set to true (see keepRunning set to false - what does it really do on Android?).
来源:https://stackoverflow.com/questions/20519427/saving-socket-io-client-on-phonegap-resume-or-disconnecting-it-on-pause