Similar to https://forums.garmin.com/developer/connect-iq/i/bug-reports/simulator-doesn-t-call-glanceview-onupdate-even-though-more-than-30-seconds-passed-since-app-was-stopped (which is a similar bug on sim on devices without liveUpdate)
For devices with liveUpdate, it works for the 1st time in the sim, but then when restarting the app it's usually stuck: it calls initialize but onLayout, onUpdate are never called (not even after 10 minutes), and in this case we either see a blank white screen or the black screen with the CIQ triangle (as we saw when the app was stopped).
The code is the same:
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
(:glance)
class WidgetGlanceView extends WatchUi.GlanceView {
const TIME_FORMAT = "$3$:$4$:$5$";
public function initialize() {
log("g.initialize");
GlanceView.initialize();
}
public function onLayout(dc as Dc) as Void {
log("g.onLayout");
}
public function onShow() as Void {
log("g.onShow");
}
public function onHide() as Void {
log("g.onHide");
}
public function onUpdate(dc as Dc) as Void {
log("g.onUpdate");
var text = formatTimestamp(TIME_FORMAT, null);
var width = dc.getWidth();
var height = dc.getHeight();
var font = Graphics.FONT_GLANCE;
var justification = Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER;
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK);
dc.clear();
dc.drawText(width/2, height/2, font, text, justification);
}
function formatTimestamp(format as String, ts as Number?) as String {
var m = ts != null ? new Time.Moment(ts) : Time.now();
var t = Time.Gregorian.info(m, Time.FORMAT_SHORT);
return Lang.format(
format,
[
(t.month as Number).format("%02d"), // depends on FORMAT_SHORT
t.day,
t.hour.format("%02d"),
t.min.format("%02d"),
t.sec.format("%02d"),
]);
}
}
SDK: 4.1.4, device: fenix6xpro
Output after restarting the app:
1657460787 g.initialize