ActivityInfo to dataField

Is there anybody who has the problem with showing and ActivityInfo.... data in datafield? I tested to show totalAscent or elapsedDistance in it and it works in simulator, but it shows empty datafield in a watch. I don't know why. I'm sorry. It's my first time when I try to play with this. I read many topics on this forum, but I can't find where I have the problem. I know that DataFields have no access to lap data, but I think, it has an access to ActivityInfo data.

I will be happy for any advice. (i know it is a stupid question).

this is my easy test:

function initialize() {
activityInfo = Act.getActivityInfo();
elaDist = activityInfo.elapsedDistance;
label = DistTest;
}

function compute(info) {
// See Activity.Info
if ( elaDist != null )
{
return elaDist;
}
else
{
return "0";
}
}
  • Is there anybody who has the problem with showing and ActivityInfo.... data in datafield? I tested to show totalAscent or elapsedDistance in it and it works in simulator, but it shows empty datafield in a watch. I don't know why. I'm sorry. It's my first time when I try to play with this. I read many topics on this forum, but I can't find where I have the problem. I know that DataFields have no access to lap data, but I think, it has an access to ActivityInfo data.

    I will be happy for any advice. (i know it is a stupid question).

    this is my easy test:

    function initialize() {
    activityInfo = Act.getActivityInfo();
    elaDist = activityInfo.elapsedDistance;
    label = DistTest;
    }

    function compute(info) {
    // See Activity.Info
    if ( elaDist != null )
    {
    return elaDist;
    }
    else
    {
    return "0";
    }
    }


    the code seems to be corect. I presume you're using datafield and not simpledatafield?
  • huh. I used simpledatafield in code. I haven't thought about it because it runs OK in simulator. Thanks for your help. I'll try to change it to datafield.
  • Your code captures a reference to the elapsedDistance field of the Activity.Info object on construction and never updates it. I'm guessing that the simulator reuses the Activity.Info object, and the device firmware allocate a new one every time. Just to help you understand the problem, consider that getActivityInfo() could be implemented two ways...

    function getActivityInfo() {
    var info = new Activity.Info();

    info.elapsedDistance = // ... some calculation ...

    return info;
    }


    Or it could be...

    hidden var info = null;

    function initialize() {
    info = new Activity.info();
    }

    function getActivityInfo() {
    info.elapsedDistance = // ... some calculation ...
    return info;
    }


    I'm guessing the device implements the former and simulator implements the latter. This is probably a simulator bug. The solution is to call Act.getActivityInfo() every time you want the activity information, like so...

    function initialize() {
    }

    function compute(info) {
    var activityInfo = Act.getActivityInfo()
    if ( activityInfo.elapsedDistance != null )
    {
    return activityInfo.elapsedDistance;
    }
    else
    {
    return "0";
    }
    }


    Travis
  • Thanks for all your answers. I don't know where I make a mistake. I saw "Failed invoking symbol" error or black screen only. I will do some test with it. :)