Hi all, I am developing a simple multiplayer game.
To make the things easy, given that every session is supposed to be quite
fast, if a player gets disconnected all the other players are notified of
her disconnection and the game goes on (no reconnection for the
disconnected player).
The persistent tcp connection is kept on in a couple of threads (one is
reading from the socket, the other is a looper thread waiting for the
messages to send).
I was thinking to use a service, to share the opened connection across two
or three activities. Now my question is: what kind of service should I
create? I was thinking of a non sticky one, given that if the os shuts it
down, the player will automatically be disconnected and I don't mind having
it reconnected. In this way I could also let it self kill in case of
disconnection, so that I can be sure I won't leave it active when the user
is not playing anymore.
In that case, when I am supposed to create (and re-create) it? In this
early stage I am creating it in the onCreate() of the first launched
actiivty, but maybe it's better to create it when the user wants to play
(and thus, link it to a "login" button). What happens if I try to create it
and it is already running?
Another approach I thought of was not to use a service and to keep
everything in a singleton class that hosts the two threads (and keeps track
of the state of the game), and let the client disconnect during onPause().
Any help / consideration may be appreciated,
Thanks in advance,
Federico
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en