Android: 'back' button event

Hello!

Is there any way to know when 'back' button on the phone is pressed? I'd like to exit the game when this button is pressed, and not hide it (if hidden, after touching the icon the second time - the game resumes from the previous point and does not restart).

thanks

Word on the forums is that we'll be able to handle the back button as the escape keycode in the upcoming RC2.

Any news on the back button feature?

2 Answers

2

The "escape" key label appears to be mapped to the back button on the android platform in the final release of Unity 3.0. As far as other mappings I've found that the "menu" key label is mapped to the menu key and that that MonoBehaviours will get an "OnApplicationPause" + true call when the home button is pressed and an "OnApplicationPause" + false when the application is brought back as the current process. I've not found a mapping for the search button as of yet.

Does it work on IOS mobil devices too? THX!

Could you also post the code required to make the game run in the background after the back button is pressed ? thanks.

You can't run an application in the background on Android.

Thank you VERY VERY Much RitchParker, this helped me a lot in creating my android game which needs to be on the pause screen when the user presses the Back Key or Menu Key.

write this your scripts (KeyCode.Escape is code for native "Back" button on Android):

if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); }

No Doubt it will work try this one.i tried also.

but that closes the app, how to set it to go to the previous scene?

Please don't add new questions as comments to 3yr old threads. But the answer is simple: replace Application.Quit(); with Application.LoadLevel("YourPreviousLevel");

hi,,balasubbaiahapps !!! it work. your code helpful. tank you very much..!

I know this is closed, however It would be nice if when testying with Unity Remote the back button would be recognised.

this will make the app quit completely,how to resume the app after its reopened?