• 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
0
Question by wangqw1215 · Nov 02, 2011 at 11:56 AM · android

how to quit from android

i build an android version app and deploy it, but when push the return button , the app cant quit as pushing home button in iphone, what can i do? thank you

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

5 Replies

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

Answer by DaveA · Nov 03, 2011 at 06:51 AM

I use the 'back' button to quit.

 function Update ()
 {
     if (Input.GetKey(KeyCode.Escape))
     {
             if (Application.platform == RuntimePlatform.Android)
             {
                    Application.Quit();
             }
     }
 }
Comment
Add comment · Show 3 · 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 paulaceccon · Nov 27, 2012 at 09:36 PM 0
Share

Hi, @DaveA. Doing this, that menu with "Do you really want to quit...", standard in Android, is called? Or the application just quit without asking again for the user? Thks.

avatar image DaveA · Dec 06, 2012 at 01:08 AM 0
Share

I'm not seeing that confirmation in my apps, so I would think you would add your own if you want that.

avatar image Fattie · Nov 20, 2014 at 04:10 PM 0
Share

dudes, wouldn't a "suspend" concept be more natural? however, it does not seem to be offered by Unity right ?

avatar image
3

Answer by save · Nov 02, 2011 at 12:27 PM

The architecture is structured so the app pauses when you for instance receive a phone call or pressing home. An app won't use much resources when paused. When pressing the home button on the iPhone it will also pause the application.

However when an app pauses it calls OnApplicationPause() so you're able to do something like this:

OnApplicationPause () {
    Application.Quit();
    //or
    System.Diagnostics.Process.GetCurrentProcess().Kill();
}

But it's not recommended. You should just let it continue in the background as when the user gets a phone call, he or she would most likely want to continue after hanging up.

Instead you could make a quit-button in the app for killing it entirely, and before that you have control over saving important data.

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 Apptention · Dec 12, 2013 at 06:04 AM

 PlayerPrefs.Save();

 var pt = System.Diagnostics.Process.GetCurrentProcess().Threads;

 for(var p in pt){
       p.Dispose();
 }

 System.Diagnostics.Process.GetCurrentProcess().Kill();
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 stevethorne · Dec 12, 2013 at 09:41 PM 0
Share

Upvoting this because I've had many issues with Application.Quit() in the past on Android. $$anonymous$$illing the process has always fixed these problems for me.

avatar image
0

Answer by Madsen · Nov 30, 2012 at 12:00 PM

I would not recoment to use: System.Diagnostics.Process.GetCurrentProcess().Kill(); with Android. I had some strange behavior, that the Writings to the Player-Prefs with PlayerPrefs.SetString where just gone, afte using that code. Application.Quit(); will do.

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 dojoman · Feb 14, 2016 at 05:57 PM

 void OnApplicationPause(bool pauseStatus) {
     
         if(pauseStatus) {
             System.Diagnostics.Process.GetCurrentProcess().Kill();
         }
         
     }

This is my lifesaver! Thanks a lot guys. It perfectly works for Android when i need to restart the application via deep linking in order to send different parameters via external url to the application.

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.

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

10 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

Related Questions

Problem with "Saved by batching" 0 Answers

Unable to execute dex 0 Answers

mouseOrbit script for android 0 Answers

Bizarre Missing Assembly 'Common' Error 0 Answers

Different physics behaviour on (iOS, Android and PC) 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