Using dynamic expressions, you can bind data that appears on a surface of your app–such as a tile or complication–to a particular data source. An example of such a data source is heart rate data that the platform can read. After you've established this binding, the system updates the data in your tiles and complications automatically.
Create dynamic data bindings
To create a dynamic data binding, define a variable that uses a dynamic data type. Associate this variable with the data stream that you want to use.
For example, you can fetch values related to the system clock and health information, as shown in the following code snippet.
val systemTime = DynamicInstant.platformTimeWithSecondsPrecision() val steps: DynamicInt32 = PlatformHealthSources.dailySteps()
DynamicInstant systemTime = DynamicInstant.platformTimeWithSecondsPrecision(); DynamicInt32 steps = PlatformHealthSources.dailySteps();
You can also create dynamic values from constant expressions and perform arithmetic operations on any dynamic value, as shown in the following snippet:
val dynamicValue = DynamicInt32.constant(1).plus(2)
DynamicInt32 dynamicValue = DynamicInt32.constant(1).plus(2)
List of possible dynamic data types
Wear OS supports the following dynamic data types:
In addition, you can transform the data type using built-in capabilities, such as the following:
DynamicInt32supports conversion to a
DynamicDurationlets you extract specific parts, such as the seconds part of a duration, as
Use a limited number of dynamic expressions on each screen
The system has a limit on the number of dynamic expressions that it can process simultaneously on a particular screen. The system converts any additional dynamic expressions to static values.
Wear OS considers constant expressions to be dynamic expressions, too. For example, the following code snippet contains 4 dynamic expressions:
constant(2)expression, which is implied by the value