Compose の状態
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Compose ベースのアプリで状態を確立して管理する方法と、状態の変化に応答するように UI を構成する方法について学びます。オブザーバブルな状態を作成する方法、再コンポーズや構成変更で状態を保持する方法、最適なデータフローを実現するためにコンポーザブルを構造化する方法を確認します。
要点
- アプリの状態がコンポーザブル内部にある場合は、
remember
を使用して、再コンポーズ全体で状態を保持します。
rememberSaveable
を使用して、構成の変更をまたいで状態を保持します。
- 状態ホイスティングとは、状態をコンポーザブルの呼び出し元に移動するプログラミング パターンです。可能な場合は、状態ホイスティングを使用して、コンポーザブルの再利用性とテスト可能性を高めます。
ViewModel
クラスを使用して、公開状態をオブザーバブル状態ホルダーに保持し、状態を適切にカプセル化して、UI の信頼できる単一のソースを作成します。
リソース
このガイドを含むコレクション
このガイドは、Android 開発の幅広い目標を網羅する、厳選されたクイックガイド コレクションの一部です。
Compose の基本(動画コレクション)
この動画シリーズでは、さまざまな Compose API を紹介し、利用可能な API とその使用方法を簡単に説明します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。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,["# State in Compose\n\n\u003cbr /\u003e\n\nLearn how to establish and manage state in your Compose-based app and how\nto configure the UI to react to changes in state. See how to create observable\nstates, how to retain state across recompositions or configuration changes, and\nhow to structure your composables for optimal data flow. \n\nKey points\n----------\n\n- If your app's state is internal to a composable, use [`remember`](/reference/kotlin/androidx/compose/runtime/package-summary#remember(kotlin.Function0)) to persist the state across re-composition.\n- Use [`rememberSaveable`](/reference/kotlin/androidx/compose/runtime/saveable/package-summary#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)) to persist the state across configuration changes.\n- *State hoisting* is a programming pattern where you move the state to the caller of a composable. Where possible, use state hoisting to make the composable more reusable and testable.\n- Use the [`ViewModel`](/reference/androidx/lifecycle/ViewModel) class to hold an exposed state in an observable state holder, better encapsulating the state and creating a single source of truth for the UI.\n\nResources\n---------\n\n- [Codelab: State in Jetpack Compose](/codelabs/jetpack-compose-state#0)\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Compose basics (video collection)\n\nThis series of videos introduces various Compose APIs, quickly showing you what's available and how to use them. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/compose-basics) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]