탐색 지도 상호작용 권장사항
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 페이지에서는 앱에서 탐색 지도와 상호작용하기 위한 권장사항을 설명합니다.
가능한 경우 NavigationView
대신 SupportNavigationFragment
사용
SupportNavigationFragment
는 NavigationView
수명 주기 콜백을 편리하게 처리하기 위한 래퍼이므로 이러한 콜백을 직접 관리할 필요가 없습니다. 이 메서드는 오류가 적게 발생하며 앱에서 탐색을 사용하는 기본 방법입니다. SupportNavigationFragment
를 사용할 때는 NavigationView
수명 주기 이벤트를 호출하지 마세요.
NavigationView
를 사용하는 경우 수명 주기 메서드를 호출할 때 엄격한 순서 사용
NavigationView
는 탐색 지도를 호스팅하고 Android 활동 및 프래그먼트와 같이 수명 주기 이벤트를 긴밀하게 따라 이러한 수명 주기 이벤트가 호출될 때 특정 작업을 실행합니다. NavigationView
은 NavigationView#onCreate
및 NavigationView#onStart
에서 여러 초기화를 실행하고 NavigationView#onStop
및 NavigationView#onDestroy
에서 정리하며 다른 수명 주기 이벤트가 처리될 때도 실행합니다.
NavigationView
수명 주기 메서드는 Android 활동이나 프래그먼트의 경우와 동일한 의미를 갖습니다. 예를 들어 NavigationView
의 onCreate()
는 Android 활동 또는 프래그먼트의 수명 주기 콜백에 의해 대략적으로 변환되고 호출되어야 합니다. NavigationView
수명 주기 콜백은 Android 수명 주기 콜백과 동일한 순서로 기반을 두고 호출되므로 이러한 NavigationView 메서드의 강력한 순서가 필요합니다. 그렇지 않으면 메모리 누수, UI 오류, 위치 업데이트 안 됨 등의 문제가 발생할 수 있습니다.
Android 활동 수명 주기에 관한 자세한 내용은 Android 개발자 문서의 활동 수명 주기 개념 섹션을 참고하세요.
다음 표는 지정된 수명 주기 메서드 후에 다른 수명 주기 메서드를 호출해야 하는 시점을 보여줍니다.
수명 주기 메서드 |
활동 수명 주기에서 호출되는 위치 |
어떤 수명 주기 메서드 후에 호출되나요? |
onConfigurationChanged()
|
UI가 포그라운드에 있고 구성이 변경될 때 호출됩니다.
|
항상 onStart() 뒤
|
onTrimMemory()
|
활동이 백그라운드에 있을 때 호출됩니다.
|
항상 onPause() 뒤
|
onSaveInstance()
|
활동이 소멸되기 전에 호출됩니다.
|
항상 onStop() 뒤
|
해당 닫기 메서드를 먼저 호출하지 않고 이러한 수명 주기 메서드를 여러 번 호출하지 마세요. 또한 이러한 Android 수명 주기 콜백 중 일부가 앱 자체에서 관리되고 생성 또는 시작 후 NavigationView
가 프래그먼트에 추가되는 경우 앱은 Navigation SDK를 올바르게 초기화하기 위해 적절한 순서로 특정 메서드를 직접 호출해야 합니다.
이러한 메서드 사용에 관한 추가 안내는 Navigation SDK 데모 앱을 참고하세요.
NavigationView
를 사용하는 경우 활동 또는 프래그먼트에서 수명 주기 이벤트를 호출합니다(둘 다 아님).
수명 주기 메서드의 엄격한 순서를 유지하려면 이러한 이벤트를 순서대로 수신하는 활동 또는 프래그먼트 수명 주기 콜백에서 호출하세요. 이 접근 방식을 사용하면 앱이 프래그먼트와 활동 간에 조정할 필요가 없고 중복 호출이 발생하지 않습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003ePrioritize using \u003ccode\u003eSupportNavigationFragment\u003c/code\u003e over \u003ccode\u003eNavigationView\u003c/code\u003e for simplified lifecycle management and error reduction.\u003c/p\u003e\n"],["\u003cp\u003eWhen using \u003ccode\u003eNavigationView\u003c/code\u003e directly, ensure strict adherence to the Android lifecycle order when invoking its lifecycle methods to prevent issues like memory leaks and UI errors.\u003c/p\u003e\n"],["\u003cp\u003eInvoke \u003ccode\u003eNavigationView\u003c/code\u003e lifecycle events exclusively from either the activity or the fragment to maintain order and avoid duplicate calls.\u003c/p\u003e\n"]]],[],null,["# Navigation map interaction best practices\n\nThis page explains best practices for interacting with the Navigation map in\nyour app.\n\nUse `SupportNavigationFragment` instead of `NavigationView`, whenever possible\n------------------------------------------------------------------------------\n\n`SupportNavigationFragment` is a wrapper for the convenience of handling the\n`NavigationView` lifecycle callbacks, so you don't need to manage these\ncallbacks themselves. This method is less error-prone and the preferred way to\nuse Navigation in your app. When using `SupportNavigationFragment`, be sure not\nto invoke `NavigationView` lifecycle events.\n\nIf using `NavigationView`, use strict ordering when invoking lifecycle methods\n------------------------------------------------------------------------------\n\n`NavigationView` hosts the Navigation map and closely follows the lifecycle\nevents as Android activities and fragments, taking specific actions when these\nlifecycle events are invoked. `NavigationView` executes multiple initializations\non `NavigationView#onCreate` and `NavigationView#onStart`, and cleanups on\n`NavigationView#onStop` and `NavigationView#onDestroy`, as well as when other\nlifecycle events are processed.\n\n`NavigationView` lifecycle methods have the same meaning as they do for Android\nactivities or fragments. For example, `onCreate()` of `NavigationView` roughly\ntranslates to and should be invoked by lifecycle callbacks from the Android\nactivity or fragment. Since the `NavigationView` lifecycle callbacks are based\non and invoked in the same order as the Android lifecycle callbacks, strong\nordering of these NavigationView methods is required. Otherwise, you may\nexperience [memory\nleaks](/maps/documentation/navigation/android-sdk/memory-best-practices), UI\nerrors, location not being updated, and other issues.\n\nFor more information about the Android activity lifecycle, see the\n[Activity-lifecycle concepts](https://developer.android.com/guide/components/activities/activity-lifecycle#alc)\nsection in the Android developer documentation.\n\nThe following table shows when other lifecycle methods should be invoked, after\nspecified lifecycle methods:\n\n| Lifecycle method | Invoked where in the activity lifecycle | Invoked after which lifecycle method |\n|----------------------------|-------------------------------------------------------------------------|--------------------------------------|\n| `onConfigurationChanged()` | Invoked when the UI is in the foreground and the configuration changes. | Always after `onStart()` |\n| `onTrimMemory()` | Invoked when an activity is in the background. | Always after `onPause()` |\n| `onSaveInstance()` | Invoked before an activity is destroyed. | Always after` onStop()` |\n\nDon't call these lifecycle methods multiple times without calling the\ncorresponding closing method first. In addition, keep in mind that if some of\nthese Android lifecycle callbacks are managed by the app itself, and the\n`NavigationView` is added to the fragment after creation or start, the app\nshould call the specific methods themselves in proper order in order to\ncorrectly initialize the Navigation SDK.\n\nFor additional guidance on using these methods, see the [Navigation SDK demo\napp](https://github.com/googlemaps-samples/android-navigation-samples/blob/4afba69715ebf6c176a2eb438f86d06c23065e7f/navigation-sample/app/src/main/java/com/example/navigationapidemo/NavViewActivity.kt#L279).\n\nIf using `NavigationView`, invoke lifecycle events from the activity or fragment, not both\n------------------------------------------------------------------------------------------\n\nTo keep the strict ordering of the lifecycle methods, invoke these events from\neither the activity or fragment lifecycle callbacks, which receive these events\nin order. This approach ensures that apps don't need to coordinate between\nfragments and activities and cause duplicate calls."]]