In my applications, I build up as much drawable state as I can in onLayout(), and then I just draw stuff in onUpdate(). When I do this in the simulator, everything works just fine. When I do it on the device, my drawables don't appear. I traced it back to the fact that the Dc passed to onLayout() has the dimensions [0, 148]. The end result is that the draw calls all execute and nothing is rendered.
The following testcase illustrates.
class PositionSampleView extends Ui.View {
var width;
var height;
function onLayout(dc) {
width = dc.getWidth();
height = dc.getHeight();
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_BLACK);
dc.clear();
var twidth = dc.getWidth();
var theight = dc.getHeight();
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
dc.drawLine(0, 0, twidth, theight);
var dims = [ width, height ];
dc.drawText(1, 1, Gfx.FONT_SMALL, dims.toString(), Gfx.TEXT_JUSTIFY_LEFT);
dims = [ twidth, theight ];
dc.drawText(1, 15, Gfx.FONT_SMALL, dims.toString(), Gfx.TEXT_JUSTIFY_LEFT);
}
}
It looks like this is happening because of the SLIDE_LEFT transition that occurs when loading an app. If you build the above code as a watch-app, when you load the app, you'll notice the diagonal line that is drawn starts out vertical, and lays down as the animation plays. This does not occur with the SLIDE_RIGHT transition when you exit the app, or with the vertical transitions used by widgets.