アプリ DataStore を使用して設定をローカルに保存

DataStore

DataStore には、Preferences DataStore と Proto DataStore の 2 種類の実装があります。

  • Preferences DataStore は Key-Value ペアを格納します。値は、String、Boolean、Integer などの Kotlin の基本データ型にできます。複雑なデータセットは保存されません。定義済みのスキーマは必要ありません。Preferences Datastore の主なユースケースは、ユーザー設定をデバイスに保存することです。
  • Proto DataStore はカスタムデータ型を格納します。proto 定義をオブジェクト構造にマッピングする事前定義スキーマが必要です。

関連記事