• 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
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
Necronomicron
arcone
AgentKnopf
BlackPanda
Bunny83
schlenger
off99555
binarybehemoth
hardartcore
annaqeeb
correia55
SpinyPirate
NEVER-SETTLE
guetta18
OdColmen
And 5 more...

People who like this

20 Show 0
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
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
anilgautam
Bunny83
Creator347
AshwaniKumar
raptorkwok
zephyr7
HEATH3N
richfriedel
csomakk
lacas8282
Thiagocgp
Necronomicron
srmols
Oxygeniium
arcone
And 44 more...

People who like this

59 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 MainCamera. (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

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
bdave
fedemoglia
dylanHart
hobnob
vikasgoyal
Aamer
Harinezumi
Gnejs
samukavera
correia55
manthanpatel
melihaksoy
EliasFazel
ch15solito
tdx110
And 1 more...

People who like this

16 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

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
stevendale
elKarkayu
guetta18
tdx110

People who like this

4 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

I Have Another Question? 1 Answer

Application.Quit needs to be called twice? 0 Answers

OnEditorQuit? 1 Answer

Make a UI button quit the exe, Unity 5 2 Answers

OnSceneExit? 3 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