Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    20
    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:
    20
    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:
    336
    Bump. Running into the same issue. Anyone using any alternatives on the Quest?
     
  4. mfuad

    mfuad

    Joined:
    Jun 12, 2018
    Posts:
    334
    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:
    336
    Hi, I ended up just using OnApplicationPause(), which works fine!
     
    Ali_V_Quest, Nilzfar and mfuad like 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?
     
    Nilzfar, Skibitsky, jmorange and 3 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:
    52
    Bump, this is still a thing.
     
    cjsawyer and (deleted member) like this.
  9. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    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:
    501
    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:
    5
    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:
    3
    Just lining up here. Can't believe the SDK does not expose this.
     
  15. abhijeetk829-

    abhijeetk829-

    Joined:
    Oct 31, 2022
    Posts:
    4
    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:
    23
    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:
    23
    There seems to be an issue on the issue tracker here if anyone wants to vote on it
     
  18. unity_03BA514BAC145D0E9AB3

    unity_03BA514BAC145D0E9AB3

    Joined:
    Feb 18, 2023
    Posts:
    8
    3 years and this is still a thing? Sucks
     
  19. BigRedzz

    BigRedzz

    Joined:
    Jul 17, 2023
    Posts:
    2
    We just need a few more votes here to get it at least on Unity's radar!
     
    AndreasWang and georges-m like this.
  20. Suraj_Sangve

    Suraj_Sangve

    Joined:
    Jul 15, 2022
    Posts:
    1
    Can any know how to solve this quit issue in quest 2?
     
  21. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Thanks
     
  22. Draxidious

    Draxidious

    Joined:
    Sep 8, 2023
    Posts:
    2
    +1 for the application quit. We are hitting the 4 year mark on this.