Issue
I want to store the data exactly when Application.Quit() method get called. Basically I want one callback method that get called one time during application life cycle, just when application killed by operating system of the device.
With iOS, I managed to work with following line of code:
void OnApplicationQuit()
{
//if (pauseStatus)
//{
DataStorage.StoreLastOpenedDay(DateTime.Now.Day);
DataStorage.StoreLastOpenedMonth(DateTime.Now.Month);
DataStorage.StoreLastOpenedYear(DateTime.Now.Year);
//}
}
But I got information that in Android, OnApplicationQuit method didn't get called by the running activity.
So what is alternative exist in Android for implementing same thing as like iOS? I can't use OnApplicationPause method because it get called multiple times when any external process happen when your application is running for ex. phone call, in app purchase related popups etc... I want code to be executed only once when application get killed.
Please share your side suggestions about this.
Solution
On Android, Application.Quit()
calls OnApplicationQuit()
, but only from inside the Unity runtime.
This means that if you have the application paused in background, and the OS decides to kill it, OnApplicationQuit()
will not be called at all.
Basically, to ensure that your app saves the data, you'll need to juggle with OnApplicationPaused()
and OnApplicationFocus()
, but this means that you won't be able to perform the save exactly once per lifetime of the app.
Answered By - Galandil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.