Skip to main content
Inspiring
August 11, 2020

How to capture exit event on exiting from the OS on Quest

Anyone know which event to handle to get in before the OS terminates the app in Unreal to do an auto save on exit?
On PC in Unreal the Game instance's Shutdown event works but not on Quest.

So the user scenario is when you click terminate app in the Oculus menu bar, how does the app know it's being terminated in Unreal?

    This topic has been closed for replies.

    4 replies

    Inspiring
    November 21, 2022

    I try using "Application Will Terminate Delegate" or "Application Will Enter Background Delegate" but neither seem to work. any other solution?

    Honored Contributor
    November 22, 2022

    you need to enable the app to write on external storage (android permissions, i recommend doing this on begin play of the app),

    Participant
    October 10, 2023

    Because ouclus sdk didnt implement Application Will Terminate Delegate with oculus you need to use native java method in unreal. That what I did.

    1. Added JNI native method at GameInstance as

    extern "C" JNIEXPORT void JNICALL Java_com_epicgames_ue4_GameActivity_OnAppTerminated(JNIEnv* jenv, jobject thiz)
    {
    UPVPGameInstance::NotifyServerLeaving(); // this is static method

    UE_LOG(LogTemp, Error, TEXT("ApplicationWillTerminateDelegate"));
    }
    2. Added UPL XML with code and included it on build:
    <?xml version="1.0" encoding="utf-8"?>
    <root xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- optional additions to the GameActivity class in GameActivity.java -->
    <gameActivityClassAdditions>
    <insert>
    <![CDATA[
    private native void OnAppTerminated();
    ]]>
    </insert>
    </gameActivityClassAdditions>
    <!-- -->
    <gameActivityOnDestroyAdditions>
    <insert>
    <![CDATA[
    OnAppTerminated();
    ]]>
    </insert>
    </gameActivityOnDestroyAdditions>
    </root>

    3. If you are developing multiplayer game and would like to notify server about that exit you need to send custom udp message on server (you can't do http because you need time for handshake and you have no time for it)