संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
नेविगेशन कंट्रोलर, नेविगेशन के मुख्य सिद्धांतों में से एक है. यह
नेविगेशन ग्राफ़ को होल्ड करता है और उन तरीकों को दिखाता है जिनसे आपके ऐप्लिकेशन
तय करें.
नेविगेशन कॉम्पोनेंट का इस्तेमाल करते समय, नेविगेशन कंट्रोलर बनाया जाता है
NavController क्लास का इस्तेमाल करके. NavController सेंट्रल है
नेविगेशन एपीआई. यह ट्रैक करता है कि उपयोगकर्ता ने किन डेस्टिनेशन पर विज़िट किया है. साथ ही,
एक से दूसरे डेस्टिनेशन पर जाने में उपयोगकर्ता की मदद करता है. इस गाइड में बताया गया है कि
NavController आपके ऐप्लिकेशन में.
Jetpack Compose का इस्तेमाल करते समय NavController बनाने के लिए, कॉल करें
rememberNavController():
valnavController=rememberNavController()
आपको कंपोज़ेबल हैरारकी में, NavController की वैल्यू बढ़ानी चाहिए. यह
यह इतना उच्च होना चाहिए कि जिन कंपोज़ेबल को रेफ़रंस की ज़रूरत है
शामिल हैं.
ऐसा करने से, आपको दो तथ्यों की जानकारी देने के लिए NavController का इस्तेमाल करने की सुविधा मिलती है.
कंपोज़ेबल को स्क्रीन के बाहर अपडेट किया जा सकता है. यह इन सिद्धांतों का पालन करता है:
स्टेट करना.
व्यू
अगर View यूज़र इंटरफ़ेस (यूआई) फ़्रेमवर्क का इस्तेमाल किया जा रहा है, तो अपने NavController को वापस पाया जा सकता है
कॉन्टेक्स्ट के हिसाब से, इनमें से किसी एक तरीके का इस्तेमाल करें:
अपना नेविगेशन ग्राफ़ डिज़ाइन करें: ग्राफ़ जोड़ने के तरीके की जानकारी देने वाली गाइड
NavController में सेव किया जा सकता है, जिसमें आपके ऐप्लिकेशन के सभी डेस्टिनेशन शामिल हैं.
किसी डेस्टिनेशन पर जाना: डेस्टिनेशन पर पहुंचने के लिए,
आपके नेविगेशन ग्राफ़ में एक डेस्टिनेशन से दूसरे पर जाने के लिए NavController.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. 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,["# Create a navigation controller\n\nThe navigation controller is one of the [key concepts](/guide/navigation#types) in navigation. It\nholds the navigation graph and exposes methods that allow your app to move\nbetween the destinations in the graph.\n\nWhen using the [Navigation component](/reference/androidx/navigation/package-summary), you create a navigation controller\nusing the [`NavController`](/reference/androidx/navigation/NavController) class. [`NavController`](/reference/androidx/navigation/NavController) is the central\nnavigation API. It tracks which destinations the user has visited, and allows\nthe user to move between destinations. This guide demonstrates how to create a\n`NavController` in your app.\n\nFor information on how to add a navigation graph to your `NavController`, see\n[Design your navigation graph](/guide/navigation/design). `NavController` provides a few different ways\nto navigate to the destinations in its graph. For more, see [Navigate to a\ndestination](/guide/navigation/use-graph/navigate).\n| **Note:** Each `NavHost` you create has its own corresponding `NavController`. The `NavController` provides access to the `NavHost`'s graph.\n\nCompose\n-------\n\nTo create a `NavController` when using Jetpack Compose, call\n[`rememberNavController()`](/reference/kotlin/androidx/navigation/compose/package-summary#rememberNavController(kotlin.Array)): \n\n val navController = rememberNavController()\n\nYou should create the `NavController` high in your composable hierarchy. It\nneeds to be high enough that all the composables that need to reference it can\ndo so.\n\nDoing so lets you to use the `NavController` as the single source of truth for\nupdating composables outside of your screens. This follows the principles of\n[state hoisting](/jetpack/compose/state#state-hoisting).\n\nViews\n-----\n\nIf you are using the Views UI framework, you can retrieve your NavController\nusing one of the following methods depending on the context:\n\n**Kotlin:**\n\n- [`Fragment.findNavController()`](/reference/kotlin/androidx/navigation/fragment/package-summary#(androidx.fragment.app.Fragment).findNavController())\n- [`View.findNavController()`](/reference/kotlin/androidx/navigation/package-summary#%28android.view.View%29.findNavController%28%29)\n- [`Activity.findNavController(viewId: Int)`](/reference/kotlin/androidx/navigation/package-summary#(android.app.Activity).findNavController(kotlin.Int))\n\n**Java:**\n\n- [`NavHostFragment.findNavController(Fragment)`](/reference/androidx/navigation/fragment/NavHostFragment#findNavController(androidx.fragment.app.Fragment))\n- [`Navigation.findNavController(Activity, @IdRes int viewId)`](/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,%20int))\n- [`Navigation.findNavController(View)`](/reference/androidx/navigation/Navigation#findNavController(android.view.View))\n\nTypically, you first get a `NavHostFragment`, and then retrieve the\n`NavController` from the fragment. The following snippet demonstrates this: \n\n### Kotlin\n\n val navHostFragment =\n supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment\n val navController = navHostFragment.navController\n\n### Java\n\n NavHostFragment navHostFragment =\n (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);\n NavController navController = navHostFragment.getNavController();\n\n| **Warning:** You can encounter problems when creating the `NavHostFragment` using `FragmentContainerView` or when manually adding the `NavHostFragment` to your activity using a `FragmentTransaction`. If you do so, you can cause `Navigation.findNavController(Activity, @IdRes int)` to fail if you attempt to retrieve the `NavController` in `onCreate()`. You should retrieve the `NavController` directly from the `NavHostFragment` instead, as in the preceding example.\n\nFurther reading\n---------------\n\n- **[Design your navigation graph](/guide/navigation/design):** A guide detailing how to add a graph to your `NavController` that contains all the destinations in your app.\n- **[Navigate to a destination](/guide/navigation/use-graph/navigate):** A guide detailing how to use the `NavController` to move between destinations in your navigation graph."]]