Reputation: 7947
I have an game app which occasionally plays sounds. When the phone goes into standby onPause gets called and the game knows to go silent. But when I press the button on the side of my phone to wake it up out of standby, onResume is called and the game starts running and making sounds immediately - this would all be ok except that I have the security system on where you have to swype a certain pattern to unlock and the sounds come on even before the phone is unlocked. Is there some way to detect that the phone has yet to be unlocked?
Upvotes: 0
Views: 443
Reputation: 821
You can solve this in several ways. My favorite (and most used) way is to create a pause dialog. So, inside your onPause
method you pause your sounds and your game and show this pause screen to the user. When the user get back to the game, it will still be paused, waiting for the user to click a button to resume the game. This will avoid the sounds to start playing in the lock screen.
There are other approaches here: http://android-developers.blogspot.com.br/2011/11/making-android-games-that-play-nice.html
Upvotes: 1