I’m trying to quit my game when the application is paused on Android.
void OnApplicationPause(bool pauseStatus) {
if (pauseStatus) {
Application.Quit();
}
}
When I press the home button and then go back to my game, the game only shows a black screen and doesn’t restart the game. Is this a bug? If I activate Application.Quit(); from a button the application will quit correctly, but I need the game to quit on it’s own when the Application loses focus.
I ran into the same issue. I can confirm there’s a bug that prevents the app from exiting from within the OnApplicationPause() method.
An (ugly) workaround we found was to set a flag to true inside the OnApplicationPause and then in the Update function check whether that variable is true. If so, then exit (or in our case, reload the scene).
private bool forceExit = false;
void OnApplicationPause(bool pause)
{
if (pause) this.forceExit = true;
}
void Update()
{
if (this.forceExit) Application.Quit() // or reload scene
}