Application lifecycle management

Hi,

When inside my app, pressing the Home button on the ML2 controller makes the app go through the Android APP_CMD_PAUSE, APP_CMD_TERM_WINDOW and APP_CMD_STOP status, as expected. Back on the Home Menu, my app is still shown as running with the “blue LED” at the right of its Home Menu item. Clicking again on my app Home Menu item bring it back, going through the Android APP_CMD_RESUME and APP_CMD_INIT_WINDOW status. So far, so good.

Now, when on the Home Menu, if I opt to close my app by clicking on its Home Menu item X button, it never goes through the APP_CMD_DESTROY status. In fact, it seems there’s no difference between being stopped and closed from the app point of view. So, what event is triggered by ML2 OS when an app is closed by clicking on its Home Menu item X button? Or which event should I register to be notified that my app has been closed?

As a side note, from within my app, if I press the Home button on the ML2 controller and immediately close the app by pressing the X button Home Menu, it doesn’t even have the time to go through the APP_CMD_PAUSE, APP_CMD_TERM_WINDOW and APP_CMD_STOP status, as if the X button was killing the app without giving me the opportunity to cleanly manage its lifecycle.

Is there any documentation on how ML2 OS manages application lifecycle?

Thanks.

@emaschino Are you testing a C++ app or a Unity App? When I test a standard android app , the onDestroy() function gets called.

    @Override
    protected void onDestroy() {
        Log.i("test", "onDestroy");
        super.onDestroy();
    }

Magic Leap 2 is expected to have the same lifecycle as an Android 10 device.

What version of the OS are you on?

Note, similar to android 10 swiping an app away from the recent tasks list may not trigger the onDestroy() callback. Instead of calling onDestroy(), the OS may simply kill the app’s process immediately.

I’m testing a C++ app with a template similar to the hello_xr sample from Khronos Group (OpenXR-SDK-Source/src/tests/hello_xr/main.cpp at main · KhronosGroup/OpenXR-SDK-Source · GitHub) with latest ML2 OS 1.12.0.

OK, so if the Close button on Home Menu acts as swiping and indeed kill the apps, what would be the suggested approach to gracefully close an app on ML2? Adding a “close” feature in the app GUI to manage the app shutdown?

Based on Android’s docs, it looks like overall, the best practice is to let Android handle app termination and ensure that your app’s state and resources are managed during the normal lifecycle events.

Thanks @kbabilinski. In my situation, it turns out that my C++ app is also an OpenXR app, so I had the ML2 controller menu button bound to a Quit action. This way, the OpenXR session is correctly closed and my app now reaches the APP_CMD_DESTROY status.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.