Counting seconds in a datafield

This topic came up a couple of times in the past, and there were multiple ways people do it. One of them is also what I did in some data fields, i.e:

hidden var mBatteryStatusBlink as Number = 0;

onUpdate(dc) {
    mBatteryStatusBlink += 1;
    if (mBatteryStatusBlink % 2 == 0) {
        dc.drawBitmap(x, y, batteryStatusIconDrawable);
    }
}

In the simulator it blinks once per second as I thought it will, and also on 2 of my 3 real devices I tested.

However to my surprise on real fenix6 at the beginning (before I start the activity and for the 1st 10 seconds of the activity) it blink something like 5-10 times a second. I think the reason is that next to my DF I have a built-in timer field, that counts the time in "hundreds" of seconds for the 1st 10 seconds (which interestingly the fr965 and edgeexplore2 don't do).

So I guess the better way is to save the timestamp and compare it...

Top Replies

All Replies

  • in a data field, elapsedTime or totalTime, give you ms, so easy to convert to seconds

    If you’d read the OP, you’d see the context where flocsy wants this to work before the activity is started, so none of the activity timer fields are appropriate here, as none of them increment before the activity is started.

    Both he and another poster mentioned that the use case is blinking an on-screen element.

    In the simulator it blinks once per second as I thought it will, and also on 2 of my 3 real devices I tested.

    However to my surprise on real fenix6 at the beginning (before I start the activity and for the 1st 10 seconds of the activity) it blink something like 5-10 times a second.

    I have a „blink timer“ in compute() on my Edge datafields
  • Which one is faster and which one uses more memory? I got lost here.

    Or what are the pros and cons of these:

    a) Time.now().value()
    b) System.getClockTime().sec
    c) System.getTimer()/1000

  • Hard to say. c) has fewer symbol lookups than a) and b), but an additional math step. (Thanks for fixing my typo haha)

    I think b) would be the slowest since presumably the system has to convert internal clock time (probably kept in milliseconds or seconds, and probably in UTC) to formatted local clock time (broken down into hours, minutes and seconds).

    I would probably go with c) or a).

    Or just toggle a flag in compute() like mcinner1 suggested. Sure, it may skip seconds in rare cases, but I think it's good enough for a blinking visual indicator.

    Or you could go with compute() before the activity starts / after it ends (if applicable), and ActivityInfo.elapsedTime during the activity. That would probably be a lot more code tho.