Wear OS में डाइनैमिक एक्सप्रेशन
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Wear OS की मदद से, आपकी टाइल में दिखने वाली जानकारी को डाइनैमिक तरीके से अपडेट किया जा सकता है
और Android घड़ी के विजेट भी शामिल हैं.
डाइनैमिक एक्सप्रेशन का इस्तेमाल करके, आप डेटा को बाइंड कर सकते हैं. यह डेटा आपकी
किसी खास डेटा सोर्स के लिए ऐप्लिकेशन—जैसे कि टाइल या Android घड़ी का विजेट. इसका एक उदाहरण
ऐसे डेटा सोर्स में धड़कन की दर का डेटा होता है, जिसे प्लैटफ़ॉर्म पढ़ सकता है. इसके बाद
इस बाइंडिंग को लागू करने पर, सिस्टम आपकी टाइल में डेटा को अपडेट करता है और
Android घड़ी के विजेट अपने-आप मिलते हैं.
डाइनैमिक डेटा बाइंडिंग बनाना
डाइनैमिक डेटा बाइंडिंग बनाने के लिए, ऐसा वैरिएबल तय करें जो किसी
डाइनैमिक डेटा टाइप होता है. इस वैरिएबल को उस डेटा स्ट्रीम से जोड़ें जिसे आपने
इस्तेमाल करना है.
उदाहरण के लिए, सिस्टम की घड़ी और हेल्थ से जुड़ी वैल्यू फ़ेच की जा सकती हैं
जानकारी, जैसा कि नीचे दिए गए कोड स्निपेट में दिखाया गया है.
Kotlin
val systemTime = DynamicInstant.platformTimeWithSecondsPrecision()
val steps: DynamicInt32 = PlatformHealthSources.dailySteps()
Java
DynamicInstant systemTime = DynamicInstant.platformTimeWithSecondsPrecision();
DynamicInt32 steps = PlatformHealthSources.dailySteps();
कॉन्स्टेंट एक्सप्रेशन से डाइनैमिक वैल्यू भी बनाई जा सकती हैं. साथ ही,
किसी भी डाइनैमिक वैल्यू पर अंकगणितीय संक्रियाएं, जैसा कि नीचे दिए गए स्निपेट में दिखाया गया है:
Kotlin
val dynamicValue = DynamicInt32.constant(1).plus(2)
Java
DynamicInt32 dynamicValue = DynamicInt32.constant(1).plus(2)
संभावित डाइनैमिक डेटा टाइप की सूची
Wear OS में इन डाइनैमिक डेटा टाइप इस्तेमाल किए जा सकते हैं:
इसके अलावा, आप पहले से मौजूद क्षमताओं का इस्तेमाल करके, डेटा टाइप को पूरी तरह बदल सकते हैं, जैसे
जैसे:
DynamicInt32
इसका इस्तेमाल करके DynamicString
में बदलने की सुविधा देता है
format()
.
DynamicDuration
की मदद से, कुछ हिस्से एक्सट्रैक्ट किए जा सकते हैं, जैसे कि सेकंड का हिस्सा
एक अवधि का, DynamicInt32
ऑब्जेक्ट के तौर पर.
हर स्क्रीन पर सीमित संख्या में डाइनैमिक एक्सप्रेशन का इस्तेमाल करना
सिस्टम पर प्रोसेस किए जा सकने वाले डाइनैमिक एक्सप्रेशन की संख्या की सीमा तय होती है
एक साथ काम कर सकते हैं. सिस्टम किसी भी अतिरिक्त वैल्यू को कन्वर्ट करता है
स्टैटिक वैल्यू के लिए डाइनैमिक एक्सप्रेशन का इस्तेमाल करता है.
Wear OS, कॉन्स्टेंट एक्सप्रेशन को भी डाइनैमिक एक्सप्रेशन मानता है. इसके लिए
उदाहरण के लिए, नीचे दिए गए कोड स्निपेट में चार डाइनैमिक एक्सप्रेशन हैं:
plus()
ऑपरेशन.
animate()
ऑपरेशन.
constant(1)
एक्सप्रेशन.
constant(2)
एक्सप्रेशन, जो2
plus()
डाइनैमिक एक्सप्रेशन.
DynamicInt32.constant(1).plus(2).animate()
आपके लिए सुझाव
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया."],[],[],null,["# Dynamic expressions in Wear OS\n\nWear OS supports dynamic updates to information that appears in your [tiles](/training/wearables/tiles)\nand [complications](/training/wearables/tiles/complications).\n\nUsing dynamic expressions, you can bind data that appears on a surface of your\napp--such as a tile or complication--to a particular data source. An example of\nsuch a data source is heart rate data that the platform can read. After you've\nestablished this binding, the system updates the data in your tiles and\ncomplications automatically.\n\nCreate dynamic data bindings\n----------------------------\n\nTo create a dynamic data binding, define a variable that uses a\n[dynamic data type](#data-types). Associate this variable with the data stream that you\nwant to use.\n\nFor example, you can fetch values related to the system clock and health\ninformation, as shown in the following code snippet.\n| **Note:** To access the data in [`PlatformHealthSources`](/reference/androidx/wear/protolayout/expression/PlatformHealthSources), you must [request a\nruntime permission](/training/permissions/requesting) in your app. \n\n### Kotlin\n\n```kotlin\nval systemTime = DynamicInstant.platformTimeWithSecondsPrecision()\nval steps: DynamicInt32 = PlatformHealthSources.dailySteps()\n```\n\n### Java\n\n```java\nDynamicInstant systemTime = DynamicInstant.platformTimeWithSecondsPrecision();\nDynamicInt32 steps = PlatformHealthSources.dailySteps();\n```\n\nYou can also create dynamic values from constant expressions and perform\narithmetic operations on any dynamic value, as shown in the following snippet: \n\n### Kotlin\n\n```kotlin\nval dynamicValue = DynamicInt32.constant(1).plus(2)\n```\n\n### Java\n\n```java\nDynamicInt32 dynamicValue = DynamicInt32.constant(1).plus(2)\n```\n\n### List of possible dynamic data types\n\nWear OS supports the following dynamic data types:\n\n- [`DynamicBool`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicBool)\n- [`DynamicColor`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicColor)\n- [`DynamicDuration`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicDuration)\n- [`DynamicFloat`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicFloat)\n- [`DynamicInstant`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicInstant)\n- [`DynamicInt32`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicInt32)\n- [`DynamicString`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicString)\n\nIn addition, you can transform the data type using built-in capabilities, such\nas the following:\n\n- `DynamicInt32` supports conversion to a `DynamicString` using [`format()`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicInt32#format()).\n- `DynamicDuration` lets you extract specific parts, such as the seconds part of a duration, as `DynamicInt32` objects.\n\nUse a limited number of dynamic expressions on each screen\n----------------------------------------------------------\n\nThe system has a limit on the number of dynamic expressions that it can process\nsimultaneously on a particular screen. The system converts any additional\ndynamic expressions to static values.\n\nWear OS considers constant expressions to be dynamic expressions, too. For\nexample, the following code snippet contains 4 dynamic expressions:\n\n1. The `plus()` operation.\n2. The `animate()` operation.\n3. The `constant(1)` expression.\n4. The `constant(2)` expression, which is implied by the value `2` in the `plus()` dynamic expression.\n\n DynamicInt32.constant(1).plus(2).animate()\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Migrate to ProtoLayout namespaces](/training/wearables/tiles/migrate-to-protolayout)\n- [Side-effects in Compose](/develop/ui/compose/side-effects)\n- [AGSL Quick Reference](/develop/ui/views/graphics/agsl/agsl-quick-reference)"]]