rabbit-escape
rabbit-escape copied to clipboard
Keeps playing when I press the power button on Android
On Android, If I start a level, then press the power button to switch off the phone, the game keeps playing.
It should pause.
I tried to add
public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) { setPaused(world, true); return true; } return super.onKeyDown(keyCode, event); }
into AndroidGameActivity class but it seems like doesn't work. Any suggestions about it ?
I would expect that when when the power button is pressed, we would get an onPause
or onStop
notification, and we could pause the game when that happened.
Some of my research on that topic is here: https://www.artificialworlds.net/blog/2015/06/18/code-for-detecting-when-you-leave-an-android-app/
Maybe we're not getting that call, or maybe we are not dealing with it right?
You are totally right. I fixed the issue by adding onPause
in AndroidGameActivity
class. Called togglePaused()
then updatePauseButton(true)
. This method pause the game after clicking power button and updates the button also. I could not push my solution for some reason but if you want you can check and imporve it.
Awesome! Did you fork the project on github? You can't push to my version - you have to push to a fork you own, and then make a pull request in the web UI https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request.