Class WorkoutSample


public final class WorkoutSample extends SessionSample

A completed workout: what kind, how long, and the totals the platform computed for it.

Totals are nullable on purpose. A workout recorded without a heart-rate sensor has no energy total, and reporting that as zero would put a false 0 kcal into every summary. null means "not measured"; zero means "measured, and it was zero".

  • Method Details

    • create

      public static WorkoutSample create(WorkoutActivityType activityType, long startMillis, long endMillis)
      Creates a workout spanning [startMillis, endMillis].
    • getActivityType

      public WorkoutActivityType getActivityType()
      The activity, mapped onto this API's shared vocabulary. See getPlatformCode() when you need exactly what the platform said.
    • getPlatformCode

      public int getPlatformCode()

      The raw platform activity constant -- an HKWorkoutActivityType on iOS or an ExerciseSessionRecord exercise type on Android -- or -1 when unknown.

      This is the fidelity escape hatch for the deliberately partial WorkoutActivityType vocabulary. It is platform-specific by definition: the same integer means different things on the two platforms, so branch on getActivityType() first and only reach for this when you must.

    • setPlatformCode

      public void setPlatformCode(int platformCode)
      Records the raw platform activity constant. Called by ports.
    • getTotalEnergy

      public HealthQuantity getTotalEnergy()
      Energy burned across the workout, or null when not measured.
    • setTotalEnergy

      public void setTotalEnergy(HealthQuantity totalEnergy)
      Sets the energy total.
    • getTotalDistance

      public HealthQuantity getTotalDistance()
      Distance covered, or null when not measured.
    • setTotalDistance

      public void setTotalDistance(HealthQuantity totalDistance)
      Sets the distance total.
    • getActiveDurationMillis

      public long getActiveDurationMillis()
      Time actually exercising, excluding pauses. Falls back to the wall duration when the platform did not report it separately.
    • setActiveDurationMillis

      public void setActiveDurationMillis(long activeDurationMillis)
      Sets the paused-time-excluded duration.
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class HealthSample