탐색 컨트롤러는 탐색의 주요 개념 중 하나입니다. 탐색 그래프를 보유하며 앱이 그래프의 대상 간에 이동할 수 있는 메서드를 노출합니다.
탐색 구성요소를 사용할 때 NavController 클래스를 사용하여 탐색 컨트롤러를 만듭니다. NavController는 중앙 탐색 API입니다. 사용자가 방문한 대상을 추적하고 사용자가 목적지 간에 이동할 수 있도록 합니다. 이 가이드에서는 앱에서 NavController를 만드는 방법을 보여줍니다.
NavController에 탐색 그래프를 추가하는 방법에 관한 자세한 내용은 탐색 그래프 설계를 참고하세요. NavController는 그래프의 대상으로 이동하는 몇 가지 다른 방법을 제공합니다. 자세한 내용은 대상으로 이동을 참고하세요.
탐색 그래프 설계: 앱의 모든 대상이 포함된 NavController에 그래프를 추가하는 방법을 자세히 설명하는 가이드입니다.
대상으로 이동:NavController를 사용하여 탐색 그래프에서 대상 간에 이동하는 방법을 자세히 설명하는 가이드입니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 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."]]