I have a socket (stored in class Communicator) connect to server. When it connected, I pass it through some activities by getApplication() like this:
((CustomApllication<Communicator>)getApplication())
.setObjectStore(communicator);
And I can get it:
communicator = ((CustomApllication<ICommunicator>) getApplication())
.getObjectStore();
The problem is when user press back, home key or call coming, the activity closed and when back, I cannot get this socket.
I wanna save state of socket whenever user exit activity. When they back, a socket always avaiable and can connect to server. How can I do this?
So if your Application is being shutdown by the system you can’t reclaim that socket. The best you can do is simply close the socket down when the application shuts down, and figure out a way to properly restore the connection when the application is restored. So you’ll need to persist whatever state is required to rebuild your socket on startup. You could persist some of this data in the preferences, filesystem, etc.