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 /
This question was closed Oct 20, 2018 at 11:23 AM by pako for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by wags · Nov 05, 2014 at 08:26 PM ·

HELP with OnApplicationQuit().. ANDROID

Hi!

I tried to look for the answer online but no one helps me :(

My problem is i want to save PlayerPrefs when the player close the application not using my game exit button. It doesnt save the data in Android. But it works perfectly in Unity editor. Please help thanks.. btw sorry for bad english.

here's my code:

void OnApplicationQuit()

{

  PlayerPrefs.SetInt("Score", cur_score);
  PlayerPrefs.Save();

}

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 wags · Nov 05, 2014 at 06:43 PM 0
Share

Btw way my game goes like this.

In the Start() i get the value of plyerprefs score

public int cur_score = 0;

void Start() { //The purpose of this line is to get the Score value when the game starts so that if //the player stop the game i'll just reload this value on OnApplcaitionQuit(); //cos i dont want to save the changes in the PlyerPrefs(Score) until the player didnt //finish the level. cur_score = PlayerPrefs.GetInt("Score"); }

here:

void OnApplicationQuit()

{

PlayerPrefs.SetInt("Score", cur_score); PlayerPrefs.Save();

}

does this makes sense? :( Please help!! Sorry for bad english. Thank you so much!

avatar image areejyahya · Oct 20, 2018 at 10:45 AM 0
Share

I'm use windows platform, but I have the same problem when I running my project (not editor ) Any body can help me????

avatar image pako areejyahya · Oct 20, 2018 at 11:25 AM 0
Share

Hey @areejyahya your problem is different from the OP. Please post a new question, and add as much details as possible.

3 Replies

  • Sort: 
avatar image
8
Best Answer

Answer by pmaloo · Sep 02, 2015 at 12:35 PM

This is how Android has been designed.

OnApplicationPause corresponds to onPause/onResume events of the activity.
OnApplicationQuit corresponds to onDestroy event of activity lifecycle.

According to android docs, you are guaranteed to get a call back for onPause but anything after it may not be called. Therefore, you may not get a call to OnApplicationQuit if Android destroys the activity after onPause(Pre Honeycomb) or onStop.

For more details on Android activity life cycle events, please visit http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle.

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
0

Answer by osum4est · Mar 27, 2015 at 04:39 PM

Hi! A few months too late... but I'm been having the same problem. Have you gotten OnApplicationExit() to work?

If not, just use OnApplicationPause(). That gets called whenever you switch to a different app or close the app!

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 ritesh_khokhani · Sep 02, 2015 at 10:39 AM

Hey,

With my experience playerprefs may/may not save when it is saved/changed in OnApplicationQuit()

White in case of OnApplicationPause() it is getting called suddenly!

Note: Experimented with Android platform only!

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

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

No Overload for method 'Instantiate' takes '7' arguments? 4 Answers

How to add collision detection between two game objects? 2 Answers

(C#)OnTriggerEnter collider only works on one game object. 0 Answers

Global name space error c# 0 Answers

SetActive() not working 2 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