Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
avatar image
20
Question by anilgautam · Dec 26, 2012 at 09:51 AM · quitexitapplication.quit

How to Exit Application in Android on Back Button

Hello All I need code to exit my application when I press back button on android device. But It seems that " Application.Quit()" is not executing. Please help

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
59
Best Answer

Answer by ina · Dec 26, 2012 at 10:32 AM

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

or in .js

 function Update(){
   if (Input.GetKeyDown(KeyCode.Escape)) 
    Application.Quit(); 
 }
Comment
Add comment · Show 5 · 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 vfxjex · Aug 18, 2013 at 11:39 PM 0
Share

wow this was very helpful thanks :)

avatar image rodude123 vfxjex · Dec 05, 2014 at 11:42 PM 0
Share

this peice of text you have written is no an answer, you should have typed it above in the comment section.

avatar image KeepTrying · May 20, 2014 at 10:01 AM 0
Share

Thank you, how to make it global ? Cause it work only in the scene that the script is atached. In my case the $$anonymous$$ainCamera. (NO_OB Here).

avatar image Roixo KeepTrying · Jan 11, 2018 at 08:20 PM 0
Share

To make it global, use a DontDestroyOnLoad Game Object

Include the code in the Game Object builded in this tutorial:

link text

avatar image geopaulm · Sep 18, 2014 at 08:54 AM 4
Share

How to just pause the application and not quit? I mean put it into backround like normal backbutton?

avatar image
16

Answer by zzeeshann · May 15, 2016 at 03:01 PM

 if (Input.GetKeyUp(KeyCode.Escape))
         {
             if (Application.platform == RuntimePlatform.Android)
             {
                 AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
                 activity.Call<bool>("moveTaskToBack", true);
             }
             else
             {
                 Application.Quit();
             }
         }
 

This code is in C# if the user is on Android device or on PC the app will exit.

Comment
Add comment · Show 1 · 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 ultron5 · May 31, 2016 at 01:21 AM -1
Share

what language is this? and post with some explanations..

avatar image
4

Answer by Muhammad Salman · Jun 01, 2016 at 06:03 AM

It will only work in the case of android only. if(Input.GetKeyDown(KeyCode.Escape)) {

Application.Quit();

}

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Solved] Exit scene OnCollisionEnter not working 2 Answers

Can I make my Android game close if you leave the game on the title screen? 1 Answer

How to end a game with ESC button. 1 Answer

Unity 5 - ExitApplication(); causes Crash 1 Answer

"Application" word in code not recognized. 1 Answer


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