Understanding Activity class

I have a watchface app and want to access data from the device (Edge 520 plus).  I was advised to try using the Activity class, but so far am unsuccessful.  I don't really understand in this context what an activity is in this case - do I need to somehow initialise an activity?  The SDK documentation is pretty vague.

I thought I could do this using Activity.getActivityInfo().  This returns a non-null object.  However all fields return null.

For example I have:

var info = Activity.getActivityInfo();
var value = info.currentPower;

This is just using "Toybox.Activity".

The simulator is connected to a power meter so should be returning non-null vales.

What am I missing.  Do I need to start an activity?  If so how?  

An example would be useful.

  • See the recordsample in the SDK.  You create a session then start recording.

  • Hi Jim.

    I do not want to record, I just want to display data.  I am using Activity class, not ActivityRecording.  Does that makes sense?

    Thanks.

  • You could try just enabling the sensor, but then you get the info is in Sensor.getInfo() and not in Activity.getActivityInfo().

  • I think that we first need to determine what kind of app you want to create.

    I have a watchface app and want to access data from the device (Edge 520 plus).

    The edge520plus device doesn't support watch faces, so this isn't even a viable option. If you want to display data while the edge520plus is being used to record an activity (typically a Ride for this device) you'd want to create a data field. If you want to display some quick data from the widget loop, you'd want to write a widget. If you're planning to take control of the device and sensors, then you want to implement a watch app.

    Given what you've described so far, it sounds like you want to implement a data field. You can create a data field project in Eclipse by clicking File > New > Connect IQ Project and selecting Data Field at the second page.

    There are two types of data field supported by ConnectIQ.

    1. Simple: A simple data fields allows you some control over the text that is displayed, but no real control over anything else
    2. Complex: A complex data field is much more flexible. You control the data and the presentation, but it requires a bit more coding to get it to work.

    If the data you want to access is in the Activity.Info class, you will have access to this from the compute() method of the data field. Most of the fields will be null until you start playing back a .FIT file or you simulate data. Both of these things can be done from the Simulation > FIT Data menu.

  • Dear Travis.  Thank you for gettting back to me.

    Apologies for the typo - I am creating a "Watch App" and taking full control of the device. Reason is there are a large number of data fields generated by our products, and for now it is easier to handle all of these together in an app.  I think data fields will be useful and we will implement down the road.

    I need access to heart rate, speed/cadence, power sensors, as well as GPS data on the Edge itself. 

    Going back to original question, how do I access this data through the Activity class?  Is this even teh best way to go about it?  Are there any examples?

    Thank you.

  • Well, there are at least two ways to go about this.

    The first way would be to get the current Activity.Info from the system via a call to Activity.getActivityInfo(). The hitch here is that you're asking for activity data, and some of that data will not be valid if you're not recording an activity. So, depending on the data you want, you may have to create an ActivityRecording.Session. The RecordSample app should provide enough code to get you going on that. If you don't care about the recorded data in the .FIT file, you can just discard it when your app exits.

    The second way is to use the functionality in the Ant, AntPlus, Sensor, and Position modules to gather the data. It seems that for your needs, at least initially, you'll just want to to enable location events and a few sensors, and then report the data provided by the callbacks that you register. The Sensor sample app shows how to register for and receive sensor updates, and the previously mentioned RecordSample shows how to register for and receive position updates.

  • We recently made a change that made it more difficult to find the sample apps... Assuming you're on windows, they are in C:\Users\<user>\AppData\Roaming\Garmin\ConnectIQ\Sdks\<sdk>\samples.

  • Ok, I had found the samples.  Thank you Travis.  I have already implemented ActivityRecording, but want to be able to view data regardless of whether a recording is in progress or not.

    It is not clear from documentation that in order to have valid Activity data you need an ActivityRecording session in progress. Since on Garmin data screens you can still see this data, it isn't obvious to me at least that you would need a recording session in progress to access that data.  Activity is useful to have as for example it gives you the best speed (GPS or speed sensor), altitude (baro or gps) etc.  Also if I put my app on an Edge520 I dont have access to ANTPlus speed sensor.

    Anyway, thank you for the clarification.  I will go another route for now.

  • When you use native sensors in an device app/watch app or a widget, you want to enable the sensors you use (heart rate for example)

    Sensor.setEnabledSensors([Sensor.SENSOR_HEARTRATE,Sensor.SENSOR_BIKEPOWER]);

    Sensor.getInfo() will then allow you to get data from those sensors once connected if you are recording or not.

    But this is what gets the device to connect to native sensors, and also gets the info from those native sensors recorded to the .fit if you are recording

    If you want GPS info, (again, device app or widget) you also need to turn that on:

    Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));

    In the case of a data field, these are both handled outside of CIQ.