The simulator always calls compute[info] before onUpdate[dc]. On my VAHR, the opposite mostly happens if the data field is on the first screen.
Although it may not seem like a big issue, I spent a couple of hours to realize that this was the reason why my app worked fine on the simulator but crashed on the real device. I had a global variable which was initialized in compute, and used in onUpdate. As it was null before compute, the app crashed on the real device when onUpdate was called first, but it never crashed in the simulator.
I first thought of reporting it as a bug because it isn't nice when simulator and devices don't work exactly in the same way. But someone might say that it was my mistake not to check for null in onUpdate or to give it a value in initialize[].
So I'm reporting this just as a "warning" :-]
Code to test/reproduce: [replace square by round brackets]
Run this in the sim and on a real device and you'll probably get different results...
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
class ComputeOrUiUpdateView extends Ui.DataField {
hidden var mWhatComesFirst = "";
function initialize[] {
DataField.initialize[];
}
function onLayout[dc] {
}
function compute[info] {
if [mWhatComesFirst.length[] == 0]
{
mWhatComesFirst = "compute[info]\nwas first";
}
}
function onUpdate[dc] {
View.onUpdate[dc];
if [mWhatComesFirst.length[] == 0]
{
mWhatComesFirst = "onUpdate[dc]\nwas first";
}
dc.setColor[Gfx.COLOR_BLUE, Gfx.COLOR_TRANSPARENT];
dc.drawText[dc.getWidth[]/2, dc.getHeight[]/2, Gfx.FONT_MEDIUM, mWhatComesFirst, Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER];
}
}