Acknowledged
CIQQA-4701

ActivityRecording.Session.discard() does not work

I modified the Record Sample to discard the recording instead of save, but the FIT file was still sent to my mobile Connect app.

  • I'm also curious to see the result of Session.discard(), as well. Doe it return true or false?

  • And you see "stop and discard recording" in the log?

  • I am using version 9.2.0 of the SDK and compiling with the 3.0.0 API for the Vivoactive 3.

    Here is a simplified test case based on the Record Sample in the SDK sample directory:

    //
    // Copyright 2015-2021 by Garmin Ltd. or its subsidiaries.
    // Subject to Garmin SDK License Agreement and Wearables
    // Application Developer Agreement.
    //
    
    import Toybox.ActivityRecording;
    import Toybox.Graphics;
    import Toybox.Lang;
    import Toybox.System;
    import Toybox.WatchUi;
    import Toybox.Sensor;
    
    class BaseInputDelegate extends WatchUi.BehaviorDelegate {
    
        private var _view as RecordSampleView;
    
        //! Constructor
        //! @param view The app view
        public function initialize(view as RecordSampleView) {
            BehaviorDelegate.initialize();
            _view = view;
        }
    
        public function onKey(evt as KeyEvent) as Boolean {
            
            if (!_view.isSessionRecording()) {
                _view.startRecording();
             } else {
                _view.stopRecording();
             }
    
            return true;
        }
    
    }
    
    class RecordSampleView extends WatchUi.View {
    
        private var _session as Session?;
        public var heartRate;
        public var _hrString;
    
        //! Constructor
        public function initialize() {
            View.initialize();
            // start heart rate monitor
            Sensor.setEnabledSensors([Sensor.SENSOR_HEARTRATE]);
            Sensor.enableSensorEvents(method(:onSnsr));
    
        }    //! Handle sensor updates
        //! @param sensorInfo Updated sensor data
        public function onSnsr(sensorInfo as Info) as Void {
            heartRate = sensorInfo.heartRate;
    
            if (heartRate != null) {
                _hrString = heartRate.toString() + " bpm";
            } else {
                _hrString = "Heart Rate";
            }
    
            WatchUi.requestUpdate();
        }
    
    
    
        //! Stop the recording
        public function stopRecording() as Void {
            if ((Toybox has :ActivityRecording) && isSessionRecording() && (_session != null)) {
                System.println("stop and discard recording");
                _session.stop();
                _session.discard();
                _session = null;
                System.exit();
            }
        }
        //! Start recording a session
        public function startRecording() as Void {
            _session = ActivityRecording.createSession({:name=>"Strength"});
            _session.start();
            WatchUi.requestUpdate();
        }
    
        //! Load your resources here
        //! @param dc Device context
        public function onLayout(dc as Dc) as Void {
        }
    
       //! Update the view
        //! @param dc Device context
        public function onUpdate(dc as Dc) as Void {
            // Set background color
            dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_WHITE);
            dc.clear();
            dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
            dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight());
            dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_WHITE);
    
            if (Toybox has :ActivityRecording) {
                // Draw the instructions
                if (!isSessionRecording()) {
                    dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_WHITE);
                    dc.drawText(dc.getWidth() / 2, dc.getHeight() / 2, Graphics.FONT_MEDIUM, "push button to start recording", Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
                } else {
                    var x = dc.getWidth() / 2;
                    var y = dc.getFontHeight(Graphics.FONT_XTINY);
                    dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_WHITE);
                    dc.drawText(x, y, Graphics.FONT_MEDIUM, "Recording...", Graphics.TEXT_JUSTIFY_CENTER);
                    y += dc.getFontHeight(Graphics.FONT_MEDIUM);
                    dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_WHITE);
                    dc.drawText(x, y, Graphics.FONT_MEDIUM, _hrString, Graphics.TEXT_JUSTIFY_CENTER);
                }
            } else {
                // tell the user this sample doesn't work
                dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_WHITE);
                dc.drawText(dc.getWidth() / 2, dc.getWidth() / 2, Graphics.FONT_MEDIUM, "This product doesn't\nhave FIT Support", Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
            }
        }
    
        //! Get whether a session is currently recording
        //! @return true if there is a session currently recording, false otherwise
        public function isSessionRecording() as Boolean {
            if (_session != null) {
                return _session.isRecording();
            }
            return false;
        }
    
    }