Dynamic expressions in Wear OS

Wear OS supports dynamic updates to information that appears in your tiles and complications.

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.

Kotlin

val systemTime = DynamicInstant.platformTimeWithSecondsPrecision()
val steps: DynamicInt32 = PlatformHealthSources.dailySteps()

Java

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:

Kotlin

val dynamicValue = DynamicInt32.constant(1).plus(2)

Java

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:

  • DynamicInt32 supports conversion to a DynamicString using format().
  • DynamicDuration lets you extract specific parts, such as the seconds part of a duration, as DynamicInt32 objects.

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:

  1. The plus() operation.
  2. The animate() operation.
  3. The constant(1) expression.
  4. The constant(2) expression, which is implied by the value 2 in the plus() dynamic expression.
DynamicInt32.constant(1).plus(2).animate()