Suppose I have three activities A,B, and C. These activities all use a socket connection to receive data. The socket connection is a Telnet connection, so it can't be closed and reconnected arbitrarily.
If the current back stack is A > B > C, Activity A
may be destroyed by Android, so I can't close the socket in onDestroy()
method, otherwise Activity C
would not be able to receive data from the socket.
I want to close the socket when the app is terminated. I can manually close it when I press the BACK on the root activity. However, if the app is killed when it is on the background, how do I handle this situation to close the socket and release related resource?
Thank you!!