• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Feb 27, 2015 at 01:37 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
42
Question by gnoblin · Aug 21, 2010 at 12:33 AM · android

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

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dave 5 · Sep 21, 2010 at 06:10 AM 0
Share

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

avatar image Mani · Oct 06, 2010 at 05:30 PM 0
Share

Any news on the back button feature?

avatar image RitchParker · Oct 26, 2010 at 10:03 PM 0
Share

So was this mapped to escape in the final release?

2 Replies

  • Sort: 
avatar image
46
Best Answer

Answer by RitchParker · Oct 28, 2010 at 04:08 AM

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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Balint · May 10, 2014 at 07:35 PM 0
Share

Does it work on IOS mobil devices too? THX!

avatar image blastoformity7 · Dec 11, 2015 at 07:15 AM 0
Share

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

avatar image tanoshimi · Dec 11, 2015 at 07:20 AM 0
Share

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

avatar image blastoformity7 tanoshimi · Dec 11, 2015 at 08:00 AM 0
Share

thanks for replying, I want my game to resume after its relaunched from the home screen in android, basically imitating the behaviour of the app when the Home button is pressed.

avatar image tmendez blastoformity7 · Jun 23, 2017 at 09:00 PM 0
Share

I believe as of now (Unity 5.5/5.6) you can run apps in the background in Android. At least Hearthstone found a way to do it.

avatar image diliupg tanoshimi · Feb 13, 2019 at 11:49 AM 0
Share

it doesn't run but stays suspended in the background

avatar image Chamandana · Jun 13, 2016 at 06:17 AM 0
Share

Thank you VERY VERY $$anonymous$$uch 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 $$anonymous$$ey or $$anonymous$$enu $$anonymous$$ey.

avatar image
47

Answer by lbalasubbaiahapps · Sep 30, 2011 at 02:55 PM

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.

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liwizy · Jul 20, 2014 at 08:27 AM 1
Share

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

avatar image tanoshimi · Jul 20, 2014 at 08:46 AM 4
Share

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

avatar image yewchunyen tanoshimi · Feb 09, 2018 at 03:01 PM 0
Share

Hi, i am too new to unity. $$anonymous$$ay i know where should i add these lines?

avatar image ahmadi9112 · Feb 27, 2015 at 01:36 AM 0
Share

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

avatar image yewchunyen ahmadi9112 · Feb 09, 2018 at 03:01 PM 0
Share

Hi, i am too new to unity. $$anonymous$$ay i know where should i add these lines?

avatar image Davinder_Singh yewchunyen · May 26, 2019 at 01:25 PM 0
Share

you should add this code in void Update() method.!

avatar image TGKG · Jun 15, 2015 at 06:10 PM 0
Share

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

avatar image benjaminstrike TGKG · Oct 31, 2015 at 08:03 AM 0
Share

$$anonymous$$ake a new thread then

avatar image blastoformity7 · Dec 11, 2015 at 07:17 AM 0
Share

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

avatar image diliupg blastoformity7 · Feb 13, 2019 at 11:50 AM 1
Share

to do that you need to save the current game stats to a list/array and then on loading the game back again check for this file and load from it.

Show more comments

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 3 Android license question 2 Answers

Unity Android Market Publishing Problem 4 Answers

How can I ensure my android app will run on 2.1 (Eclair)? 1 Answer

Android: prevent phone from sleeping 2 Answers

AsyncOperation.progress still broken? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges