rabbit-escape icon indicating copy to clipboard operation
rabbit-escape copied to clipboard

Keeps playing when I press the power button on Android

Open andybalaam opened this issue 8 years ago • 4 comments

On Android, If I start a level, then press the power button to switch off the phone, the game keeps playing.

It should pause.

andybalaam avatar Mar 04 '16 22:03 andybalaam

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 ?

KaganHamzacebi avatar Oct 27 '19 15:10 KaganHamzacebi

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?

andybalaam avatar Oct 30 '19 08:10 andybalaam

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.

KaganHamzacebi avatar Oct 30 '19 09:10 KaganHamzacebi

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.

andybalaam avatar Oct 30 '19 12:10 andybalaam