Hi, I am trying to write an app and it is mostly working. I would now like to press the Back button and get the option to save/resume/delete the activity, rather than just exiting the app.
Any help would be great. Thanks.
In your input delegate, catch the back, and when you're done, return true, indicating you handled the button.
For the save/discard, that is something you have to do in your code, as you won't get the native screen. You could use confirmation/confirmation delegate for this.
I am doing that, and it works as I would expect in the Simulator, but not when it is on my watch.
just trying something simple
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 );
//! Called when this View is removed from the screen. Save the
//! state of this View here. This includes freeing resources from
//! memory.
function onHide() {
}
}
It works fine in the Simulator but not on my Forerunner 920xt
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 );
//! Called when this View is removed from the screen. Save the
//! state of this View here. This includes freeing resources from
//! memory.
function onHide() {
}
}