public final class HealthChangeBatch

  1. Object
  2. HealthChangeBatch
A set of changes since the last time a subscription was drained. Delivered to HealthChangeListener in the foreground and to HealthBackgroundListener after a background relaunch.

Constructors

public HealthChangeBatch(String subscriptionId, List<HealthDataType> types, List<HealthSample> added, List<String> deletedSampleIds, boolean resyncRequired, HealthAnchor anchor, long deadlineMillis, boolean more)Creates a batch.

Methods

public String getSubscriptionId()The subscription this batch belongs to.
public List<HealthDataType> getTypes()The types covered by this batch.
public List<HealthSample> getAdded()Samples added or updated since the last drain.
public List<String> getDeletedSampleIds()Identifiers of samples removed since the last drain.
public boolean isResyncRequired()true when the platform cursor was lost and incremental delivery cannot continue – a Health Connect change token older than 30 days, or an iOS anchor rejected after a restore from backup.
public HealthAnchor getAnchor()The cursor after this batch.
public long getDeadlineMillis()Roughly how much wall-clock time the listener has before the OS may suspend the process, in milliseconds.
public boolean hasMore()true when more changes were available than SubscriptionRequest.getMaxSamplesPerBatch() allowed.
public boolean isEmpty()true when nothing changed and no resync is needed.
public String toString()Returns a string representation of the object.

Inherited methods

Constructor details

HealthChangeBatch

public HealthChangeBatch(String subscriptionId, List<HealthDataType> types, List<HealthSample> added, List<String> deletedSampleIds, boolean resyncRequired, HealthAnchor anchor, long deadlineMillis, boolean more)
Creates a batch. Called by HealthStore; the lists are copied defensively.

Method details

getSubscriptionId

public String getSubscriptionId()
The subscription this batch belongs to.

getTypes

public List<HealthDataType> getTypes()
The types covered by this batch.

getAdded

public List<HealthSample> getAdded()
Samples added or updated since the last drain. Empty when the subscription set SubscriptionRequest.setDeliverSamples(boolean) to false, and empty when isResyncRequired().

getDeletedSampleIds

public List<String> getDeletedSampleIds()
Identifiers of samples removed since the last drain.

isResyncRequired

public boolean isResyncRequired()

true when the platform cursor was lost and incremental delivery cannot continue – a Health Connect change token older than 30 days, or an iOS anchor rejected after a restore from backup.

getAdded() is empty in that case. The app must do a full time-range read to catch up; nothing else will deliver the missed data.

getAnchor

public HealthAnchor getAnchor()
The cursor after this batch. Persisted by HealthStore automatically; exposed for apps that checkpoint against their own server – see HealthAnchor.

getDeadlineMillis

public long getDeadlineMillis()

Roughly how much wall-clock time the listener has before the OS may suspend the process, in milliseconds. About 5000 on an iOS background relaunch; Long.MAX_VALUE in the foreground.

Do cheap bookkeeping inside a background delivery – accumulate a counter, stash an identifier – and leave network calls for the next foreground.

hasMore

public boolean hasMore()
true when more changes were available than SubscriptionRequest.getMaxSamplesPerBatch() allowed. The remainder arrives in the next delivery, or immediately on HealthStore.drainChanges().

isEmpty

public boolean isEmpty()
true when nothing changed and no resync is needed.

toString

public String toString()
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())