1
\$\begingroup\$

I'm porting an FPS game to Android, and I have a question about the use of wake locks.

Should the client acquire a wake lock when it connects to a server to keep frames running at a proper rate when the player is AFK and the device is in sleep mode?

And should a wake lock be used if the game is running a listen or a dedicated server?

\$\endgroup\$
1
\$\begingroup\$

If the player is afk and the phone goes to sleep, there is no reason to keep him connected at all. Maintaining a connection will drain the player's battery and place additional stress on your servers, both for no benefit, since the player isn't using the game anyway. This means higher costs for you and (potentially) negative reviews for your game.

Instead, you should just drop the connection when the phone goes to sleep and attempt to reconnect when the phone wakes up.

If you don't want to disconnect a user without him willing it to happen, you can set FLAG_KEEP_SCREEN_ON. This will keep the phone awake as long as the app is in focus while also shouting to the user, "Hey, I'm eating your battery! You should turn me off if you're really not playing anymore!"

\$\endgroup\$
  • \$\begingroup\$ Well, it's not something that I can do, the player would lose the scores in case of accidentally pressed sleep button. The servers are ran by the community, anyway. Also most servers have idle timeouts and will kick idlers by themselves. My question was mostly technical - I thought deep sleep only slowed down the CPU, but because it turns it off completely, I apparently have no other option than to use a wake lock. \$\endgroup\$ – Triang3l Aug 21 '14 at 17:15
  • \$\begingroup\$ And yes, of course I'm using KEEP_SCREEN_ON so the screen doesn't turn off if the player is camping. \$\endgroup\$ – Triang3l Aug 21 '14 at 17:18
  • \$\begingroup\$ @SiPlus The power button on android does not put the phone to sleep. It only turns the screen off. If the screen stays off for some time, then it goes to sleep. So you shouldn't have to worry about that kind of accident. \$\endgroup\$ – Icy Defiance Aug 21 '14 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.