Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by smallbit · Oct 08, 2013 at 07:35 PM · androidapplicationquit

Application.quit() not working on android

Application quit works on escape button (back on my galaxy s2) but doesn't work when in the GUI.button.

Any ideas how can i fix it ?

i use temporal exit function which will have more things in it in the future

     if(GUI.Button(new Rect((int)menuMainX,340,240,60), "Exit")) {

                 Exit();

             }





    void Exit()
     {
         Application.Quit();
         
     }



I tried to put it directly under gui button same result.

Comment
Add comment · Show 1
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 meat5000 ♦ · Oct 08, 2013 at 08:20 PM 0
Share

Lots of peeople seem to find that Application.Quit() from an OnGUI button doesnt seem to work.

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by meat5000 · Oct 08, 2013 at 07:52 PM

You can script it for the back button but iOS and Android have a User Discretion policy on app quit these days. Basically back button will normally lose focus and pause but the app moves to background. You can set it to quit but you should show a dialogue to confirm quit for good Android practise, I believe.

I read that back button is the same as Escape key but I'm yet to try it.

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




Edit:

Just tried the following on a GUITexture in my touch routine.

 if(menuButtons.HitTest(GUIRay).name == "QuitMenuButton" && theTouch.phase == TouchPhase.Began)
             {
                 Application.Quit();
             }

It Quit the App. However Android 4.3 showed strange behaviour. The program remained inside my open apps list. If I went back to the game in the list it reloaded the game from start. So although the game quits it seems to not Unload fully.

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

Answer by satya144 · Dec 19, 2013 at 08:21 AM

Well application.quit() doesn't work in unity but after building and running it will work on your device.

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

Answer by Ereptor · Oct 08, 2013 at 07:43 PM

I haven't worked in Android before, but I know that Application.Quit(); does not work in the web version. We had to remove Quit buttons from the web version of our game, instead allowing for the user to default to the "retry" option, or simply use their browser to navigate away.

What is the convention for Android? It's possible that Application.Quit(); might not be the proper choice.

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

Answer by smallbit · Oct 08, 2013 at 07:52 PM

I have read the documentation and I know that this command wont work in PIE and web but on android should be working properly...

I have found a thread from 2011 in which one unity user used System.Diagnostics.Process.GetCurrentProcess().Kill();

instead, but there is no additional info

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

Answer by hari2015 · Feb 12, 2018 at 05:27 AM

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

20 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

Related Questions

Proper way for Quit Application 2 Answers

How do I Force Application to Quit if no internet connection available 1 Answer

How do i stop mUnityPlayer.quit() closing the entire android app? 1 Answer

Path for Assets/Textures folder File in Android 2 Answers

Some questions about unity app's tcp connection state in Android sleep mode 0 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