I have developed a game using andengine
I am facing a problem when using the power Button. If I press the POWER Button while playing the game the screen turns off and the onPause() is called as expected. But when I press the HOME button or POWER button again to turn on the screen, onResume() method is called and but the lockscreen shows up.
In the onResume() method, I resume the music of the game.
So as a result lockscreen shows up , but the game music plays in the background. I do not want to play the music in the lockscreen. Please help me solving this.Thank you
The solution is here: Activity handle when screen unlocked
By registering a
BroadcastReceiverfiltering theIntent.ACTION_SCREEN_ON,Intent.ACTION_SCREEN_OFFandIntent.ACTION_SCREEN_PRESENTactions, you will be able to handle these 3 cases:Intent.ACTION_SCREEN_OFF: When thePOWERbutton is pressed and the screen goes black.Intent.ACTION_SCREEN_ON: When thePOWERbutton is pressed again and lockscreen is showed up.Intent.ACTION_SCREEN_PRESENT: When you pass the locksreen and are back in your game.However, in my case (using a Galaxy S GT I9000 with Froyo 2.2) these actions are not called when dealing with the
HOMEbutton (and I think it’s a general behavior).One simple and quick (but maybe not the best) way to handle both
HOMEandPOWERbuttons to pause and resume your music could be to keep theonPauseandonResumemethods and use a simple boolean flag like this:Hope it helps!