public final class WorkoutConfiguration

  1. Object
  2. WorkoutConfiguration
Describes a workout about to be started.

Constructors

public WorkoutConfiguration()

Methods

public WorkoutConfiguration setActivityType(WorkoutActivityType activityType)The kind of exercise.
public WorkoutActivityType getActivityType()The configured activity.
public WorkoutConfiguration setLocationType(WorkoutLocationType locationType)Indoors or outdoors – see WorkoutLocationType, which affects whether GPS is used.
public WorkoutLocationType getLocationType()The configured location type.
public WorkoutConfiguration setKeepAliveInBackground(boolean keepAliveInBackground)Asks the operating system to keep the app running while the workout records.
public boolean isKeepAliveInBackground()Always false in this release – see setKeepAliveInBackground(boolean).
public WorkoutConfiguration addCollectedType(HealthDataType type)Asks the platform to collect this type automatically during the workout.
public List<HealthDataType> getCollectedTypes()The types requested for automatic collection.
public WorkoutConfiguration setTitle(String title)A user-visible title for the workout.
public String getTitle()The configured title, or null.

Inherited methods

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.