Appropriate way to handling exiting/onBack in an app?

Former Member
Former Member
I apologize if this has been asked before - I didn't find anything on searching.

What is the appropriate implementation for app developers to ensure proper exiting/backing out of a watch app? Currently, when I load my app onto my Fenix 3 it works well but when I press the "Back" button to exit, it crashes. The code for my main BehaviorDelegate is below.

Also - a previous version of this code was not implementing onBack, and still crashed. Any help is appreciated - thanks.

(On a related note - what is the appropriate handling for the Up/Down keys in a widget to ensure that one can cycle to the adjacent widgets? Or should they be left un-handled?)


class LoopTimerDelegate extends Ui.BehaviorDelegate
{
hidden var app;

function initialize()
{
app = App.getApp();
}

function onMenu()
{
Ui.pushView(app.getNewSettingsMenu(), new LoopTimerMenuDelegate(), Ui.SLIDE_UP);

return true;
}

function onBack()
{
// Handle exiting
Ui.popView(Ui.SLIDE_RIGHT);
return true;
}

function onKey(evt)
{
var key = evt.getKey();
var handled = false;

if (WatchUi.KEY_ENTER == key)
{
app.toggleTimer();
handled = true;
}
else if (WatchUi.KEY_DOWN == key)
{
// Reset the timer
app.resetCurrentIteration();
handled = true;
}

if (handled)
{
Ui.requestUpdate();
}

return handled;
}
}
  • Former Member
    Former Member over 10 years ago
    Apps should not be able to crash the device, so this is not caused by something you are doing wrong. I am investigating this issue.
  • Former Member
    Former Member over 10 years ago
    I have identified and reported an issue that is preventing static intializers from working in the AppBase. The sample code you provided would need to be updated to assign the vibrateData objects in the initialize function instead to work around this issue.
    (The code above is also missing "using Toybox.Attention as Attention")

    It doesn't appear this issue is related to the device crash you are seeing. That issue is still under investigation.
  • Former Member
    Former Member over 10 years ago
    I've identified the source of the crash, and the fix should be integrated in the next device software releases.

    You should be able to work around this issue for now by avoiding saving the AppBase in your delegate. Calling App.getApp() instead should prevent the crash on application exit.
  • Former Member
    Former Member over 10 years ago
    Thanks Brian - already had the work-arounds in place but thank you for the tip. Glad you were able to find the issue(s).