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.

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:
    15
    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:
    15
    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:
    742
    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:
    454
    Can hardly believe this is still a thing. @mfuad , are you still the correct person to ping about this?
     
    AndreasWang, 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.  
     
  14. rdmont

    rdmont

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

    abhijeetk829-

    Joined:
    Oct 31, 2022
    Posts:
    1
    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.
     
  16. AndreasWang

    AndreasWang

    Joined:
    Jul 31, 2019
    Posts:
    14
    I just faced this issue as well on the Quest 2 in an OpenXR project. It seems to affect Application.quitting too :(
     
  17. AndreasWang

    AndreasWang

    Joined:
    Jul 31, 2019
    Posts:
    14
    There seems to be an issue on the issue tracker here if anyone wants to vote on it
     
    tom_fv, cmersereau and nils_vixel like this.