I am developing a multi-player game application for Android. One of the participants acts as a host (the one who created the instance of the game), and each of the other participants connects to the host using bluetooth.
My question is this: this host has several threads that work for communication and contain all open connections. I read that my actions can be destroyed temporarily and later restored, and for this I have to use the onSaveInstanceState mechanism. However, I'm talking about an application that acts as a โserverโ for the game, and has open connections and threads that serve other clients, what happens to these connections and threads if the OS decides to destroy my activity? Are they discontinued? If so, what will be the recommended template for the correct implementation, how can I save the connection in the onSaveInstanceState package? it is not serializable. The same goes for threads, do I need to recreate and destroy them when destroyed and when activity is restored ?? if I hold all this state in some kind of static class representing the state of the game? If I do this, will the OS not destroy my threads / connections?
I looked at the bluetooth chat sample that comes with the SDK and I donโt handle onSaveInstanceState like that, so itโs very unclear what to do.
Thanks!
android android-lifecycle bluetooth
Eitan
source share