Class WorkoutConfiguration

java.lang.Object
com.codename1.health.workout.WorkoutConfiguration

public final class WorkoutConfiguration extends Object
Describes a workout about to be started.
  • Constructor Details

    • WorkoutConfiguration

      public WorkoutConfiguration()
  • Method Details

    • setActivityType

      public WorkoutConfiguration setActivityType(WorkoutActivityType activityType)
      The kind of exercise. Defaults to WorkoutActivityType.OTHER.
    • getActivityType

      public WorkoutActivityType getActivityType()
      The configured activity.
    • setLocationType

      public WorkoutConfiguration setLocationType(WorkoutLocationType locationType)
      Indoors or outdoors -- see WorkoutLocationType, which affects whether GPS is used.
    • getLocationType

      public WorkoutLocationType getLocationType()
      The configured location type.
    • setKeepAliveInBackground

      public WorkoutConfiguration setKeepAliveInBackground(boolean keepAliveInBackground)

      Asks the operating system to keep the app running while the workout records. Not available in this release -- passing true throws.

      Nothing honours it anywhere yet. Keeping the process alive needs either a live HKWorkoutSession, which WorkoutManager.isLiveSessionSupported() reports false for on every platform here, or an Android foreground service, which the build does not emit and for which no build hint exists. A setter that stored the request and let the workout be killed mid-run would be worse than one that refuses it: the app could not tell the difference until a user lost a workout.

      Until then, record with the app in the foreground, and write what you have collected rather than assuming the session will still be running when the user comes back.

      Throws
      • IllegalArgumentException: if keepAliveInBackground is true.
    • isKeepAliveInBackground

      public boolean isKeepAliveInBackground()
      Always false in this release -- see setKeepAliveInBackground(boolean).
    • addCollectedType

      public WorkoutConfiguration addCollectedType(HealthDataType type)
      Asks the platform to collect this type automatically during the workout. Honoured only where WorkoutManager.isSensorCollectionSupported() is true; elsewhere you must feed samples in yourself with WorkoutSession.addSamples(java.util.List).
    • getCollectedTypes

      public List<HealthDataType> getCollectedTypes()
      The types requested for automatic collection.
    • setTitle

      public WorkoutConfiguration setTitle(String title)
      A user-visible title for the workout.
    • getTitle

      public String getTitle()
      The configured title, or null.