Class SensorSessionOptions
SensorSession should behave: reconnection, where samples go,
and how stale a cached reading may be.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintThe staleness threshold in milliseconds.intThe store write-batch interval in milliseconds.The attached workout, or null.booleantruewhen the session reconnects automatically.booleantruewhen samples are written through to the health store.setAutoReconnect(boolean autoReconnect) Whether the session re-establishes a dropped link on its own.setStaleSampleMillis(int staleSampleMillis) How long a cached reading stays current, forSensorSession.getLatest(com.codename1.health.HealthDataType).setStoreBatchMillis(int storeBatchMillis) How long samples are batched before being written to the store.setWorkoutSession(WorkoutSession workoutSession) Attaches this sensor to a workout, so its samples become part of that workout's statistics and are persisted with it.setWriteToStore(boolean writeToStore) Whether received samples are written through to the platform health store.
-
Constructor Details
-
SensorSessionOptions
public SensorSessionOptions()
-
-
Method Details
-
setAutoReconnect
Whether the session re-establishes a dropped link on its own. Defaults totrue, which is almost always right -- chest straps drop out routinely as the wearer moves. -
isAutoReconnect
public boolean isAutoReconnect()truewhen the session reconnects automatically. -
setWriteToStore
Whether received samples are written through to the platform health store. Defaults to
false, and that default is deliberate.During a workout on watchOS -- and on iOS 26 and later -- the operating system is already recording heart rate into HealthKit itself. A strap that also writes its own heart-rate samples produces two overlapping sets for the same minutes, and every downstream average, maximum and chart is then computed over double-counted data.
If you are recording a workout, attach the session to it with
setWorkoutSession(WorkoutSession)instead: samples land in the workout's statistics and are persisted once, as part of the workout, when it ends.Turning this on is right when you are logging a standalone measurement the OS knows nothing about -- a weight from a scale, a blood-pressure reading from a cuff.
-
isWriteToStore
public boolean isWriteToStore()truewhen samples are written through to the health store. -
setStoreBatchMillis
How long samples are batched before being written to the store. Defaults to one minute. Writing every notification individually would mean a store round trip per second per sensor. -
getStoreBatchMillis
public int getStoreBatchMillis()The store write-batch interval in milliseconds. -
setWorkoutSession
Attaches this sensor to a workout, so its samples become part of that workout's statistics and are persisted with it.
This is the right way to feed a heart-rate strap into a recorded workout -- see the warning on
setWriteToStore(boolean). -
getWorkoutSession
The attached workout, or null. -
setStaleSampleMillis
How long a cached reading stays current, for
SensorSession.getLatest(com.codename1.health.HealthDataType). Defaults to ten seconds.Past this age
getLatestreturns null rather than a stale value, so a UI bound to it shows a dash instead of silently displaying the heart rate from before the strap fell off. -
getStaleSampleMillis
public int getStaleSampleMillis()The staleness threshold in milliseconds.
-