Skip to main content
Inspiring
May 16, 2012
Question

How to handle activate event when screen is locked.

  • May 16, 2012
  • 2 replies
  • 2456 views

Hi all,

I have an Android app that handles activate and deactivate events by saving state and pausing all the amimation and sound on the deactivate event and resuming on the activate event. This works fine, except that if the device has a lock screen enabled, what happens is this:

Game is running

Device goes to sleep

     - game pauses, saves state and shuts up

User wakes device

     - lock screen displays

     - while lock screen is up, app starts up again - playing sound and such BEHIND the lock screen

     - user unlocks the screen - adnd we are good.

Is there a way to tell when the app does not have focus - as in the lock screen is frontmost? I know you can in pure Android development. I believe it invoves knowing the current "active window".

This topic has been closed for replies.

2 replies

Known Participant
July 11, 2012

There's a blog on this at:

http://android-developers.blogspot.com/2011/11/making-android-games-that-play-nice.html

I was already doing exactly as he describes. The games I work on pause and throw up a shaded pause screen over the game with text stating to "Tap the screen to resume" when receiving the DEACTIVATE event and do nothing on the ACTIVATE event. The player much tap the screen to resume. Well, the game also listens for key events and the Back button works to unpause the screen too. (Samsung app store testers love this trick - they will start your game, screen lock the device, unlock it, then hit the Back button.)

But you may want to try the methods described in the blog. Good luck.

scober99Author
Inspiring
July 11, 2012

That's not a bad idea. Thanks!