Exit an application

Former Member
Former Member
Can't find it anywhere. How can I properly exit/stop/finish my application? Thanks!
  • Former Member
    Former Member over 10 years ago
    It seems like popping last view properly exits an application. Is it the only way?
  • Former Member
    Former Member over 10 years ago
    Popping your last view is the correct way to exit your app cleanly. There are System.exit() and System.error() methods, but these are not clean exists and will log an error.
  • What is popping the last view?
    I'm trying to implement something same as well, doing a recording and want to exit it while saving the fit file.
    I tried to use the BACK/LAP button, but after that, I can't get out of that app. (Need reboot)

    Likely cos when I mapped the back button, I only stopped & saved the session but not able to exit
  • If you want to use the back button for two different purposes (One press to save a recording session, and another press to exit) you need to handle that in your key handler.

    function onKey(evt) {
    var key = evt.getKey();
    if (key == Ui.KEY_ESC) {
    if (session != null) {
    if (session.isRecording()) {
    session.addLap();
    }
    else {
    session.save();
    session = null;
    }
    }
    else {
    Ui.popView(Ui.SLIDE_IMMEDIATE);
    }

    return true;
    }
    else if (key == Ui.KEY_ENTER) {
    if (session != null) {
    if (session.isRecording()) {
    session.stop();
    }
    else {
    session.start();
    }

    return true;
    }
    }

    return false;
    }
  • Got it... Also had to move the code around as to where I start the session. (I have it in a

    function onKey(evt) {
    ...

    if( evt.getKey() == Ui.KEY_ESC ) {
    StopSession();
    Ui.popView(Ui.SLIDE_IMMEDIATE);
    return true;
    }

    ...


    function StartSession(dc) {
    if( Toybox has :ActivityRecording ) {
    if ( session == null ) {
    session = Record.createSession({:name=>"Strength", :sport=>Record.SPORT_GENERIC, :subSport=>Record.SUB_SPORT_STRENGTH_TRAINING});
    session.start();
    Ui.requestUpdate();
    } else if( ( session == null ) && ( session.isRecording() == false ) ) {
    session.start();
    Sys.println("2nd START");
    }
    }
    }

    function StopSession(dc) {
    if( Toybox has :ActivityRecording ) {
    if( ( session != null ) && session.isRecording() ) {
    Sys.println("Session STOP");
    session.stop();
    session.save();
    session = null;
    Ui.requestUpdate();
    }
    }
    }



    Seems to be working now.
  • Former Member
    Former Member over 9 years ago
    I notice now that the simulator kills the application when you hit the back/esc button as it would normally on a watch which is great.

    I also notice though that when you use Ui.popView from the main view from software, the simulator does not kill the application. Is this meant to kill the application in the simulator? if so, I have done something wrong, if not, any chance someone from garmin can get it added in a future release?

    here is some code excerpts to explain better

    class MainView extends Ui.View {

    function onShow() {
    killTimer.start(method(:onKillTimer), 1000, false);
    }

    function onKillTimer() {
    Ui.popView(Ui.SLIDE_IMMEDIATE);
    }
    }


    I was hoping this code would kill the application in the simulator too, same as if i hit the BACK/ESC key!
  • I believe popping the main view should lead to an error on the device and the simulator. Are you getting an error in this case?
  • Former Member
    Former Member over 9 years ago
    Popping the base view of a Widget is not allowed and will cause an error, but popping the base view of a Watch App should shut it down as it does on the device. If this isn't working in the sim, we will need to update the behavior.
  • What's the correct behaviour for a watch app? once all views are popped out, should one be at the "list" of watch apps (e.g.: run / indoor run / trail / hike / golf_sc / recorder ....)
    or should it go all the way to the watch face?

    I noticed that the native watch apps goes to the watch face
    CIQ Watch Apps will go to the list of watch apps.
  • Former Member
    Former Member over 9 years ago
    This behavior depends on the product, but I think in general your observation is accurate. The native apps behave a bit differently in general (e.g. you can get to the system menu), but I do see a bit of an inconsistency when backing out of CIQ as compared to native activities. I will ask product teams and see if they want CIQ to exit to the watch when closing.

    (I think this is the case on FR920 and Fenix 3, but on VivoActive, the native modes and CIQ both exit out to the main app selection menu)