As you already stated, OnApplicationQuit()
is never actually invoked when exiting an app on the Go from the Oculus menu. The app is instead placed into a suspended state for which little can be done. Aside from hooking into native code or some android java plugin (the details thereof are not my forte), there isn't much of a known workaround for this.
Part of this reason is because the workaround really does depend on the needs of the app, saving state or PlayerPrefs
can be done in the OnApplicationPause()
method.
private void OnApplicationPause(bool isPaused)
{
if (isPaused) {
// ..
PlayerPrefs.Save();
}
}
This is probably the simplest solution, for single player/user games/apps. For multiplayer games, you can subscribe to OVR's connection state changed event and handle the user who just quit from the inversed side:
using Oculus.Platform;
using Oculus.Platform.Models;
// ...
Net.SetConnectionStateChangedCallback((Message<NetworkingPeer> message) => {
if (message.Data.State == PeerConnectionState.Closed) {
Debug.Log("The user MOST LIKELY quit the app.");
}
});
This is not a perfect solution but since OVR doesn't provide anything in their docs and they don't respond to questions on this topic in their forums, this is a decent enough workaround.
The only other option is to encourage users to click on some sort of "Quit" button from within your app which calls UnityEngine.Application.Quit()
which will indeed invoke the OnApplicationQuit()
method.
Cheers.