Exiting an app from Menu Deligate on a fr x3x

I want to exit an app based on a menu selection, and can do it just fine with popView on the vivoActive, but that doesn't work on the fr230 (and probably the 235/630).

So I tried Sys.exit() (which works fine on a 230 in BehaviourDeligate). (note: the simulator throws up an error on Sys.exit() but no error in the real devices - this has been reported to Garmin).

But from MenuDelegate, calling Sys.exit() on the va or 230, results in the "IQ!" screen, but nothing in the CIQ_LOG.txt file. (this looks like a bug to me!)

To demonstrate this problem, I created a "new>CIQ Project>watch app" in Eclipse, and in the MenuDelegate file I made the following change: (and this is all!)
function onMenuItem(item) {
if (item == :item_1) {
Sys.println("item 1");
} else if (item == :item_2) {
Sys.println("exiting");
Sys.exit();

}
}

Anyone found a clean way to exit an app on the x3x from a a menu?

(I think there are actually two bugs here - popView should work on the 230, and the "IQ!" with Sys.exit() shouldn't be there)

Thanks in advance.
  • Former Member
    Former Member over 9 years ago
    So I tried Sys.exit() (which works fine on a 230 in BehaviourDeligate).


    I think Sys.exit() should not be used in any normal situation. It's designed to exit the application with an error message.
    There's a discrepancy in documentation:
    • Programmer's Guide: To end execution of the current system with an error message of "User terminated", call exit().
    • Documentation: To end execution of the current system cleanly from any point in the app.

    Documentation says nothing about the error message.

    Anyone found a clean way to exit an app on the x3x from a menu?

    If you don't push any view in your menu, you're returned to the calling view, where onShow will be called. You can exit your app from there:

    enum {
    LOAD_NORMAL,
    LOAD_EXIT
    }

    var loadMode = LOAD_NORMAL;

    class MyMenuDelegate extends Ui.MenuInputDelegate
    {
    function initialize() {
    MenuInputDelegate.initialize();
    }

    function onMenuItem(item) {
    if (item == :exit) {
    loadMode = LOAD_EXIT;
    }
    }
    }

    class MyView extends Ui.View
    {
    function onShow() {
    if (loadMode == LOAD_EXIT) {
    Ui.popView(Ui.SLIDE_DOWN);
    }
    }
    }


    I haven't tested this, but I think this should work.
  • Thanks for the idea Teun. Tried it, and it works on the vivoactive, but not on the 230... :(

    I seem to recall seeing somewhere that with 1.2.x, Sys.exit() was supposed to be a be a clean exit as Sys.error() could be used to report an error.

    In BehaviorDelegate is it a clean exit on both a va and 230, so I'm not sure what the current state of exit() is.
  • This should be fixed in the 1.2.2 release--please let me know if you still have issues with Sys.exit().
  • Hi,

    I am having this exact issue with a FR230 in an app I am developing. I want the app to save an activity and exit the app through a menu, and Sys.exit() as well as Ui.popView end up on the infamous IQ logo screen, and then I can exit the app with the back button, and the activity is correctly installed. My app overrides the use of the back button.

    Is there any way for exiting cleanly from the app? I am on the last SDK (1.2.4)

    Best,
    Kurt.-

    Edit: It works if I exit with the default back button behaviour. But it would be nice being able to exit directly from a menu item without requiring an extra press from the user.
  • I suspect this could be something that now works in the sim, but the CIQ VM with that fix isn't in the FW for your device yet.

    As the person that started this thread, I do have code in place that handles it, but a bit differently based on the device FW.

    On the va with my app, when you "discard" it exits the app (using popView in onShow() ), but when I'm in that state and the popView doesn't work (like on a 23x), in "onUpdate()", I display a message "Recording Discarded - hit back to exit".

    "Save" is a bit different for me, as when that's picked from the menu, I display a summary of the activity in onUpdate(), (with "hit back to exit")