OnApplicationQuit() and OnDestroy() is not executed when exit app on Oculus Quest!

I am developing VR applications on oculus Quest when I press the Oculus Home button and return to Oculus Platform UI Exit Prompt, OnApplicationPause () and OnApplicationFoundations () execute normally, but when I choose the Exit button to exit my application, the application exits, but OnApplicationQuit () and OnDestroy () are not executed.


On AndroidLogCat, I see this below.
Unity know app is quit but not notice OnApplicationQuit() and OnDestroy().

Bump. Running into the same issue. Anyone using any alternatives on the Quest?

Hi @hungrybelome , can you file a bug with reproducible project so the team can properly track and take a look? Thanks!

Hi, I ended up just using OnApplicationPause(), which works fine!

3 Likes

@mfuad How is this thread marked as “Resolved” when it’s evidently not resolved? This has been an ongoing issue since the Oculus Go days. It apparently has something to do with the inherent behavior of android which suspends applications.

OnApplicationPause DOES NOT SUFFICE! App quit logic is very different from app pause logic.

The Oculus Integration package should come with a built-in android plugin written in Java which hooks into the application suspend event and automatically call some function or event which users such as ourselves can hook into. If you guys don’t want it to call OnApplicationQuit() then that is fine, but you can at least make a custom event and event listener so that we can do something like:

private void Awake()
{
    OVRPlugin.applicationSuspend += OnApplicationSuspend();
}

private void OnApplicationSuspend()
{
    // app quit logic such as leave game, etc
}

Is it really that hard for Oculus to build a Java plugin that hooks into the C# API like that?

6 Likes

Not sure how this got marked resolved. @mfuad did a ticket ever get submitted for this?

1 Like

Bump, this is still a thing.

2 Likes

I would like a fix for this as well. It prevents things like disconnecting a player from a server on quit for their avatar to be removed. Instead they stick around until the server times them out.

5 Likes

Can hardly believe this is still a thing. @mfuad , are you still the correct person to ping about this?

3 Likes

Adding to the line of devs that recognize this to be a problem and would love to see a resolution

1 Like

+1

Please yes.

Even though every OnApplicationPause(true) could lead to a possible quit, handling that is still different from an actual quit which tears down scene objects.

OnApplicationPause also doesn’t get called from a forced shutdown due to battery running out, when it’s still critical to save user progress.

To deal with these cases, we’ve implemented a hook in our Android plugin. Here’s the essential code, hope it helps anyone

public class MyReceiver extends BroadcastReceiver {
    @override
    public void onReceive(Context context, Intent intent) {
        if (action.equals("android.intent.action.ACTION_REQUEST_SHUTDOWN")) {
           UnityPlayer.UnitySendMessage("GlobalGameObject", "AndroidShutdown", "");
        }
    }
};
4 Likes

Just lining up here. Can’t believe the SDK does not expose this.

I faced this problem in a project too. I have a contingency in place using web socket. If a player disconnects on socket, the avatar is released.

I just faced this issue as well on the Quest 2 in an OpenXR project. It seems to affect Application.quitting too :frowning:

There seems to be an issue on the issue tracker here if anyone wants to vote on it

4 Likes

3 years and this is still a thing? Sucks

We just need a few more votes here to get it at least on Unity’s radar!

2 Likes

Can any know how to solve this quit issue in quest 2?