HELP with OnApplicationQuit().. ANDROID

Hi!

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

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();

}

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.

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!

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!

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