override onBack ()

Former Member
Former Member
This code work in the simulator, but on the Forerunner 920xt, pressing the Back button takes me back to the clock.

code:

using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;

var testVali = 0;

class BaseInputDelegate extends Ui.BehaviorDelegate
{
function onBack() {
testVali=testVali-1;
WatchUi.requestUpdate();
return true;
}
function onSelect() {
testVali=testVali+1;
WatchUi.requestUpdate();
return true;
}
}

class counterView extends Ui.View {

function initialize() {
View.initialize();
}

//! Load your resources here
function onLayout(dc) {
setLayout(Rez.Layouts.MainLayout(dc));
}

//! Called when this View is brought to the foreground. Restore
//! the state of this View and prepare it to be shown. This includes
//! loading resources into memory.
function onShow() {
}

//! Update the view
function onUpdate(dc) {
dc.setColor( Gfx.COLOR_TRANSPARENT, Gfx.COLOR_BLACK );
dc.clear();
dc.setColor( Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT );

dc.drawText((dc.getWidth() / 2), ((dc.getHeight() / 2) - 30), Gfx.FONT_SMALL, "Counter", Gfx.TEXT_JUSTIFY_CENTER);
dc.drawText((dc.getWidth() / 2), ((dc.getHeight() / 2) - 10), Gfx.FONT_NUMBER_HOT, testVali.toString(), Gfx.TEXT_JUSTIFY_CENTER);
}

//! Called when this View is removed from the screen. Save the
//! state of this View here. This includes freeing resources from
//! memory.
function onHide() {
}
}