Class SeriesSample
A run of measurements that share one record identity -- a beat-to-beat heart-rate trace, a cadence series.
Why this type exists
The two platforms disagree about grouping. Health Connect's
HeartRateRecord is a single record containing many samples, and
deleting it means deleting the record as a whole. HealthKit returns the
same data as many independent samples with no grouping at all.
Flattening Health Connect into individual samples loses the identity
you need in order to delete; inventing a series on iOS would claim a
grouping that is not there. So the choice is yours:
SampleQuery.setFlattenSeries(boolean) defaults to true, which gives
both platforms plain QuantitySample objects and lets cross-platform
code be identical. Turn it off when you need record identity, and
expect iOS to return series of size 1.
Storage
Values are held in parallel primitive arrays rather than a list of objects. A month of continuous heart rate is tens of thousands of points, and boxing each one is real memory pressure on a phone.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SeriesSamplecreate(HealthDataType type, long startMillis, long endMillis, long[] sampleStarts, long[] sampleEnds, double[] values, HealthUnit unit) Creates a series.longgetSampleEndMillis(int i) The end of measurementi, epoch millis UTC.longgetSampleStartMillis(int i) The start of measurementi, epoch millis UTC.doublegetSampleValue(int i, HealthUnit in) Measurementiconverted intoin.getUnit()The unit every measurement in this series is expressed in.intsize()The number of measurements in this series.toQuantitySample(int i) Measurementias a standaloneQuantitySample.toString()Returns a string representation of the object.Methods inherited from class HealthSample
equals, getDurationMillis, getEndMillis, getId, getMetadata, getRecordingMethod, getSource, getStartMillis, getType, hashCode, isInstantaneous, putMetadata, setId, setRecordingMethod, setSource
-
Method Details
-
create
public static SeriesSample create(HealthDataType type, long startMillis, long endMillis, long[] sampleStarts, long[] sampleEnds, double[] values, HealthUnit unit) Creates a series. The three arrays must be the same length and are copied defensively.
Throws
IllegalArgumentException: if the arrays are null, differ in length, orunitis null.
-
size
public int size()The number of measurements in this series. -
getSampleStartMillis
public long getSampleStartMillis(int i) The start of measurementi, epoch millis UTC. -
getSampleEndMillis
public long getSampleEndMillis(int i) The end of measurementi, epoch millis UTC. Equal to the start for an instantaneous measurement. -
getSampleValue
Measurement
iconverted intoin.Throws
IllegalArgumentException: ifinmeasures a different dimension.
-
getUnit
The unit every measurement in this series is expressed in. -
toQuantitySample
Measurement
ias a standaloneQuantitySample. Allocates, so prefer the indexed accessors when walking the whole series.The returned sample inherits this series' source, recording method and identifier -- meaning several extracted samples share one identifier, since they came from one record.
-
toString
Description copied from class:ObjectReturns 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:
toStringin classHealthSample
-