Compose में स्टेट
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Compose पर आधारित ऐप्लिकेशन में स्टेटस सेट अप और मैनेज करने का तरीका जानें. साथ ही, स्टेटस में होने वाले बदलावों पर प्रतिक्रिया देने के लिए, यूज़र इंटरफ़ेस (यूआई) को कॉन्फ़िगर करने का तरीका जानें. डेटा को मॉनिटर करने के लिए स्टेटस बनाने का तरीका जानें. साथ ही, कॉम्पोज़ेबल को फिर से कॉम्पोज़ करने या कॉन्फ़िगरेशन में बदलाव करने के दौरान स्टेटस को बनाए रखने का तरीका जानें. इसके अलावा, डेटा फ़्लो को बेहतर बनाने के लिए, कॉम्पोज़ेबल को स्ट्रक्चर करने का तरीका जानें.
प्रमुख बिंदु
- अगर आपके ऐप्लिकेशन का स्टेटस, किसी कॉम्पोज़ेबल के अंदरूनी हिस्से में है, तो फिर से कॉम्पोज़ करने के दौरान स्टेटस को बनाए रखने के लिए,
remember
का इस्तेमाल करें.
- कॉन्फ़िगरेशन में होने वाले बदलावों के दौरान, स्थिति को बनाए रखने के लिए
rememberSaveable
का इस्तेमाल करें.
- स्टेट होइस्टिंग एक प्रोग्रामिंग पैटर्न है. इसमें, स्टेट को किसी कॉम्पोज़ेबल के कॉलर पर ले जाया जाता है. जहां भी हो सके, स्टेट हॉइस्टिंग का इस्तेमाल करें, ताकि कॉम्पोज़ेबल को ज़्यादा बार इस्तेमाल किया जा सके और उसकी जांच की जा सके.
ViewModel
क्लास का इस्तेमाल करके, एक्सपोज़ की गई स्थिति को ऑब्ज़र्व किए जा सकने वाले स्टेट होल्डर में रखें. इससे स्टेट को बेहतर तरीके से कवर किया जा सकता है और यूज़र इंटरफ़ेस (यूआई) के लिए एक ही सोर्स बनाया जा सकता है.
संसाधन
ऐसे संग्रह जिनमें यह गाइड शामिल है
यह गाइड, चुने गए क्विक गाइड के कलेक्शन का हिस्सा है. इसमें Android डेवलपमेंट के बड़े लक्ष्यों के बारे में बताया गया है:
कॉम्पोज़ करने के बुनियादी तरीके (वीडियो कलेक्शन)
इस वीडियो सीरीज़ में, Compose के अलग-अलग एपीआई के बारे में बताया गया है. इससे आपको यह जानने में मदद मिलेगी कि कौनसे एपीआई उपलब्ध हैं और उन्हें कैसे इस्तेमाल किया जा सकता है.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. 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,["# State in Compose\n\n\u003cbr /\u003e\n\nLearn how to establish and manage state in your Compose-based app and how\nto configure the UI to react to changes in state. See how to create observable\nstates, how to retain state across recompositions or configuration changes, and\nhow to structure your composables for optimal data flow. \n\nKey points\n----------\n\n- If your app's state is internal to a composable, use [`remember`](/reference/kotlin/androidx/compose/runtime/package-summary#remember(kotlin.Function0)) to persist the state across re-composition.\n- Use [`rememberSaveable`](/reference/kotlin/androidx/compose/runtime/saveable/package-summary#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)) to persist the state across configuration changes.\n- *State hoisting* is a programming pattern where you move the state to the caller of a composable. Where possible, use state hoisting to make the composable more reusable and testable.\n- Use the [`ViewModel`](/reference/androidx/lifecycle/ViewModel) class to hold an exposed state in an observable state holder, better encapsulating the state and creating a single source of truth for the UI.\n\nResources\n---------\n\n- [Codelab: State in Jetpack Compose](/codelabs/jetpack-compose-state#0)\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Compose basics (video collection)\n\nThis series of videos introduces various Compose APIs, quickly showing you what's available and how to use them. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/compose-basics) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]