Switch between calls depending on device api level? (ActivityRecording vs Activity)

I have an app where Fenix5 users reported crashes wereas my F5plus worked fine. I think I tracked it down to the ActivityRecording and enums of the sport/subsport.

_session = ActivityRecording.createSession({
                :name => "Yada yada",
                :sport => Activity.SPORT_RUNNING,
                :subsport => Activity.SUB_SPORT_GENERIC
            });
F5plus is on api level 3.3 and F5 is on api level 3.1. The issue is that the enum in Activity was introduced in 3.2. Before that the enum resides in ActivityRecording.
What is the proper way to handle this? Check for api level (how?) and use
ActivityRecording.SPORT_RUNNING
if its a F5 and use
Activity.SPORT_RUNNING
if it's a newer device?
  • Hi,

    Try the following, otherwise you can check the 'monkeyVersion' from Device Settings.

    var at = Toybox.Activity has :SPORT_RUNNING ? Toybox.Activity.SPORT_RUNNING : Toybox.ActivityRecording.SPORT_RUNNING;

  • Or you can create your own const, as the only thing that matters are the numbers. BTW I think the best way is to turn on optimization to level 3. I use it in all apps, and as a side effect I don't have this problem,  because it replaces the const with their value in compile time.