Can someone explain (or point me to a document explaining ) the Suspend/Resume, Focus/Unfocus and Application Quitting flow for a Unity android application?
What I'm trying to do is detect when the user pauses or quits my app, and save their data so they can resume from the same place later.
From my experimentation, I've found that iOS apps behave in the way you would expect; OnApplicationFocus and OnApplicationPause are called at appropriate points when the app is put into the background and resumed, and OnApplicationQuit is called when the user kills the application.
However Android apps behave in a significantly different fashion;
1. Application Starts
2. OnApplicationFocus(true) is called (Gain focus)
3. User presses the Home or Running Apps button which puts the current app into the background
4. OnApplicationPause(true) is called (Pausing)
5. User selects the app from the background apps menu to make it the current app again
6. **The app re-starts entirely, rather than resuming from where it left off, as if the user had booted it for the first time**
7. The user presses the power button to turn off the screen
8. OnApplicationPause(true) is called (Pausing)
9. **OnApplicationFocus(false) is SOMETIMES called (Lose focus)**
10. The user presses the power button to turn on the screen again
11. **OnApplicationFocus(true) is SOMETIMES called (Gain focus) (if focus was previously lost)**
12. OnApplicationPause(false) is called (Resuming)
13. The user kills the app from the running apps menu
14. **OnApplicationQuit() IS NOT CALLED**
Is this expected behaviour? It seems as though, on Android, apps are never *really* in the background, since they have to restart each time the user "resumes" them. The puzzling one is why OnApplicationQuit is ***never*** called. Is the only way around this behavior to save the game each time OnApplicationPause(true) is called and load up the most-recent save data each time the application boots?
↧