[null,null,["最后更新时间 (UTC):2023-09-25。"],[],[],null,["# Navigation\n\nTry the Compose way \nJetpack Compose on Wear OS is the recommended UI toolkit for Wear OS. \n[Handle navigation using Compose on Wear OS →](/training/wearables/compose/navigation) \n\n\nAfter designing individual screens for each user journey, you might have a few vertical or single\nscreens.\nNext, you have to decide how to design these screens to work together and how to implement the\nnavigation.\n\nDesign\n------\n\n\nKeep your app's hierarchy shallow and linear, as called out in the [app design guidelines](/training/wearables/design/apps).\n\n\nTo start, your app's launcher should open the most common user journey. Design each user journey\nwith the most important content at the top. For vertical containers, use the bottom to link to\nother, less-common user journeys and the settings.\n\n\n**Figure 1.** Keep the most important content at the top of vertical containers.\n\nWhen users enter one of your screens, make sure they can use the swipe-to-dismiss gesture\nto navigate down the [back stack](/guide/components/tasks-and-back-stack).\n\nImplement the navigation\n------------------------\n\n\nWhen you implement your navigation, you have three options, described in the following sections:\n\n- Activities only, which is the recommended approach\n- Activities and fragments\n- Jetpack Navigation\n\n### Activities only\n\n\nSince vertical screens are typically one level deep, you can implement all your screens\nusing activities and without using fragments.\n\n\nWe strongly recommend this approach. It simplifies your code, and\nactivities automatically support\n[swipe-to-dismiss](/training/wearables/apps/exit#swipe-to-dismiss). This also makes\nimplementing [ambient mode](/training/wearables/apps/always-on) simpler.\n\n\n**Note:** Make your activities inherit from a\n[`ComponentActivity`](/reference/androidx/activity/ComponentActivity) if\nyou are not using fragments. The other activity types use mobile-specific UI elements you don't\nneed for Wear OS.\n\n### Activities and fragments\n\n\nYou can use [fragments](/guide/fragments) with activities in your Wear OS app. However,\nwe don't recommend this, as there isn't a clear advantage to using fragments to create a shallow and flat\narchitecture.\n\n\n**Note:** If you are using fragments, make them inherit from\n[`FragmentActivity`](/reference/androidx/fragment/app/FragmentActivity). The\nother activity types use mobile-specific UI elements you don't need for Wear OS.\n\n\nSome of the difficulties with using fragments in your Wear OS app include the following:\n\n- You must implement the swipe-to-dismiss yourself. Otherwise, when the user performs a swipe, they exit the entire app.\n- If you are using [`AmbientMode`](/reference/androidx/wear/ambient/AmbientMode), you must customize it to work properly. `AmbientMode` is set on the activity, so you have to take that into account when implementing fragments.\n\n\nTo support swipe-to-dismiss with fragments, you must wrap the fragment-containing\nview in the\n[`SwipeDismissFrameLayout`](/reference/androidx/wear/widget/SwipeDismissFrameLayout)\nclass. See\n[The swipe-to-dismiss gesture](/training/wearables/apps/exit#swipe-to-dismiss)\nfor more information. Doing this provides users a consistent experience with your app.\n\n\n**Note:** When using fragments, use\n[`FragmentManager.add`](/reference/androidx/fragment/app/FragmentTransaction#add(int,%20java.lang.Class\u003c?%20extends%20androidx.fragment.app.Fragment\u003e,%20android.os.Bundle))\nrather than\n[`FragmentManager.replace`](/reference/androidx/fragment/app/FragmentTransaction#replace(int,%20java.lang.Class\u003c?%20extends%20androidx.fragment.app.Fragment\u003e,%20android.os.Bundle))\nto support the swipe-to-dismiss gesture.\nThis helps ensure that your previous fragment renders under the top fragment while it is being\nswiped away.\n\n### Jetpack Navigation\n\n\nJetpack Navigation can work on Wear OS, but it has the same drawbacks as fragments. It adds\ndevelopment work and, because a Wear OS app's hierarchy is generally shallow and linear, it doesn't\noffer many advantages. An activity-only approach is best.\n\n\nTo fully leverage Jetpack Navigation, do the following:\n\n- Make sure every fragment uses a [`SwipeDismissFrameLayout`](/reference/kotlin/androidx/wear/widget/SwipeDismissFrameLayout) as its root, and manually use the dismiss action to go back in the navigation graph.\n- Implement a custom [`FragmentNavigator`](/reference/androidx/navigation/fragment/FragmentNavigator) that renders fragments on top of each other."]]