ナビゲーション
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Compose の方法を試す
Wear OS では、Wear OS 向け Jetpack Compose が推奨される UI ツールキットです。
ユーザー ジャーニーごとに個別の画面を設計すると、垂直方向の画面が複数ある場合や、単一の画面になる場合があります。次に、これらの画面を連携させるように設計する方法と、ナビゲーションを実装する方法を決定する必要があります。
デザイン
アプリ設計ガイドラインに記載されているように、アプリの階層は浅くリニアに保ちます。
まず、アプリのランチャーで最も一般的なユーザー ジャーニーを開くようにします。各ユーザー ジャーニーを設計する際は、最も重要なコンテンツを上部に配置します。縦型コンテナの場合は、下部を使用して、あまり一般的でない他のユーザー ジャーニーと設定にリンクします。
図 1. 最も重要なコンテンツは縦型コンテナの上部に配置します。
ユーザーがいずれかの画面に移動したときに、スワイプして閉じるジェスチャーを使用してバックスタックを下方向に移動できることを確認します。
ナビゲーションを実装する
ナビゲーションを実装する方法は次の 3 つです。次のセクションで説明します。
- アクティビティのみ(推奨)
- アクティビティとフラグメント
- Jetpack Navigation
アクティビティのみ
縦型画面は通常 1 レベルの深さであるため、アクティビティを使用して、フラグメントを使用せずにすべての画面を実装できます。
このアプローチを強くおすすめします。これによりコードが簡素化され、アクティビティはスワイプして閉じるを自動的にサポートします。また、アンビエント モードの実装も簡単になります。
注: フラグメントを使用していない場合は、アクティビティを ComponentActivity
から継承します。他のアクティビティ タイプでは、Wear OS に必要のないモバイル固有の UI 要素を使用します。
アクティビティとフラグメント
Wear OS アプリのアクティビティでフラグメントを使用できますが、フラグメントを使用して浅くフラットなアーキテクチャを作成することに明確な利点がないため、おすすめしません。
注: フラグメントを使用している場合は、FragmentActivity
から継承するようにします。他のアクティビティ タイプでは、Wear OS に必要のないモバイル固有の UI 要素を使用します。
Wear OS アプリでフラグメントを使用すると、次のような問題が発生することがあります。
-
スワイプして閉じる機能は、ご自身で実装する必要があります。そうでない場合、ユーザーがスワイプすると、アプリ全体が終了します。
-
AmbientMode
を使用する場合は、正しく機能するようにカスタマイズする必要があります。AmbientMode
はアクティビティに設定されるため、フラグメントを実装する際にはこれを考慮する必要があります。
スワイプして閉じる操作をサポートするには、フラグメントを含むビューを SwipeDismissFrameLayout
クラスにラップする必要があります。詳しくは、スワイプして閉じるジェスチャーをご覧ください。これにより、ユーザーはアプリで一貫したエクスペリエンスを得ることができます。
注: フラグメントを使用する場合、スワイプして閉じる操作をサポートするため、FragmentManager.replace
ではなく FragmentManager.add
を使用してください。これにより、スワイプされた前のフラグメントが一番上のフラグメントの下に表示されるようになります。
Jetpack Navigation
Jetpack Navigation は Wear OS で動作しますが、フラグメントと同じ欠点があります。開発作業が増え、Wear OS アプリの階層は通常浅くリニアであるため、多くのメリットはありません。アクティビティのみのアプローチが最適です。
Jetpack Navigation を最大限に活用するには、次の操作を行います。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-26 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-26 UTC。"],[],[],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."]]