Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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

Discussion in 'VR' started by BelieveXiaoShuai, Dec 18, 2019.

  1. BelieveXiaoShuai

    BelieveXiaoShuai

    Joined:
    Nov 6, 2017
    Posts:
    13
    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.
     

    Attached Files:

    Last edited: Dec 18, 2019
  2. BelieveXiaoShuai

    BelieveXiaoShuai

    Joined:
    Nov 6, 2017
    Posts:
    13
    On AndroidLogCat, I see this below.
    Unity know app is quit but not notice OnApplicationQuit() and OnDestroy().
     

    Attached Files:

  3. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    333
    Bump. Running into the same issue. Anyone using any alternatives on the Quest?
     
  4. mfuad

    mfuad

    Unity Technologies

    Joined:
    Jun 12, 2018
    Posts:
    332
    Hi @hungrybelome, can you file a bug with reproducible project so the team can properly track and take a look? Thanks!
     
  5. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    333
    Hi, I ended up just using OnApplicationPause(), which works fine!
     
    mfuad likes this.
  6. mmmshuddup

    mmmshuddup

    Joined:
    Feb 9, 2015
    Posts:
    4
    @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:

    Code (CSharp):
    1. private void Awake()
    2. {
    3.     OVRPlugin.applicationSuspend += OnApplicationSuspend();
    4. }
    5.  
    6. private void OnApplicationSuspend()
    7. {
    8.     // app quit logic such as leave game, etc
    9. }
    Is it really that hard for Oculus to build a Java plugin that hooks into the C# API like that?
     
    Skibitsky, jmorange, confy and 2 others like this.
  7. emerge-sjh

    emerge-sjh

    Joined:
    Oct 16, 2020
    Posts:
    14
    Not sure how this got marked resolved. @mfuad did a ticket ever get submitted for this?
     
    cjsawyer likes this.
  8. mrstruijk

    mrstruijk

    Joined:
    Jan 24, 2018
    Posts:
    49
    Bump, this is still a thing.
     
    cjsawyer and (deleted member) like this.
  9. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    725
    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.
     
  10. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    449
    Can hardly believe this is still a thing. @mfuad , are you still the correct person to ping about this?
     
    mrstruijk and cjsawyer like this.
  11. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    Adding to the line of devs that recognize this to be a problem and would love to see a resolution
     
    mrstruijk likes this.
  12. josros

    josros

    Joined:
    Oct 16, 2021
    Posts:
    1
  13. VirZOOM

    VirZOOM

    Joined:
    Mar 16, 2017
    Posts:
    3
    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

    Code (java):
    1.  
    2. public class MyReceiver extends BroadcastReceiver {
    3.     @override
    4.     public void onReceive(Context context, Intent intent) {
    5.         if (action.equals("android.intent.action.ACTION_REQUEST_SHUTDOWN")) {
    6.            UnityPlayer.UnitySendMessage("GlobalGameObject", "AndroidShutdown", "");
    7.         }
    8.     }
    9. };
    10.  
     
    Thomas-Mountainborn likes this.
  14. rdmont

    rdmont

    Joined:
    Sep 10, 2021
    Posts:
    1
    Just lining up here. Can't believe the SDK does not expose this.
     
unityunity