Init of datafield on the Edge?

I use my datafield on a F3. With startign a activity, the view is intanziated and the initialization-method is called. The view does it's init-procedure (setting global variables).
After ending the activity, going back to clock, startign new activity, this procedure works like before (initialization-Method is called and th eview does its init-procedure).

On the edge the datafield and the app seems to keep active after ending a activity.
A user explained that he saved the activity and started a new activity. In this situation, the initialization-Method of the view is not called. The start-Method of the app is also not called.
The activity starts new but the datafiel keeps its old data (like you would continue a activity) because the init procedure defined in the view's initializiation-method is noch processed..

Is the behavior on the edge different to clock-like devices?
What would be a good event to clear the data on start of a new activity?
  • In ConnectIQ 2.1.0, DataField provides the following APIs that will be useful to you (specifically onTimerReset())...

    - (Object) onTimerLap
    The function onTimerLap will be called when a lap is added to the current activity.

    - (Object) onTimerPause
    The function onTimerPause will be called when the activity timer goes from the running state to the paused state.

    - (Object) onTimerReset
    The function onTimerReset will be called when the current activity is ended.

    - (Object) onTimerResume
    The function onTimerResume will be called when the activity timer goes from the paused state to the running state.

    - (Object) onTimerStart
    The function onTimerStart will be called when the activity timer goes from the stopped state to the started state.

    - (Object) onTimerStop
    The function onTimerStop will be called when the activity timer goes from the running state to the stopped state.


    If you don't want to wait for the 2.1.0 SDK, you should be able to detect when the timer has stopped by examining the fields of the Activity.Info that is passed to compute()...

    hidden var prev_startTime;

    function compute(info) {

    // relies on info.startTime being null when the timer has
    // not started

    if (prev_startTime == null) {

    if (info.startTime != null) {
    // activity just started
    }
    }
    else { // prev_startTime != null

    if (info.startTime == null) {
    // activity has just ended
    }
    else if (info.startTime != prev_startTime) {
    // activity has just ended, but never set info.startTime to null
    }
    }

    prev_startTime = info.startTime;
    }
  • Hello Travis,

    thank you for your answer and your examples.
    I hoped there would be a explicit event, but I suspected the timer is the only way to check the events. So I don't need to search for other solutions...
  • In 1.2.x, I do things similar to what Travis posted for startTime, but have a few more things I look at in compute() too.. For example, in one DF, I need GPS, so I wait for a valid startLocation, and when it becomes invalid, it means things have finished, and I also keep an eye on timerTime, and if it's not changing between calls to compute(), it means the recording is paused.

    On a 230, you can record a run, save it, and you go back to the data screens for run and can start another one without restarting the run app, so I watch for things in compute(), and when these things go back to the non-recording state, I can reinitialize things to their default state.
  • Former Member
    Former Member over 8 years ago
    Jim and Travis have already touched on this, but the behavior you are seeing is not new and exclusive to the Edge. The Fenix line of watches automatically exit the active training profile after an activity is saved, but most of the Forerunner series devices do not, and will exhibit the same behavior you are seeing with Edge. Datafields are loaded and unloaded with the Activity Profile they are assigned to, and not with each activity. If you are computing data that needs to be reset at the start of each activity, you should watch for the timer time returning to 0. In the upcoming 2.1.0 and 1.3.0 versions of ConnectIQ, you can also listen for the onTimerReset event as pointed out by the others.
  • Thanks Brian,

    I havn't looked into 2.1.0. Sounds nice ;)

    Can I found somewhere a info about the SDK version supported by each device?
    Perhaps here it would be helpful:
    http://developer.garmin.com/connect-iq/compatible-devices/

    Bye
    Ronny