private val sharedPreferences : SharedPreferences = … fun getAge(): Int { return sharedPreferences .getInt(Key.Age, -1) } fun getHeight(): Int { return sharedPreferences .getInt(Key.Height, -1) } fun setAge(age: Int) { sharedPreferences .edit { putInt(Key.Age, age) } } fun setHeight(height: Int) { sharedPreferences .edit { putInt(Key.Height, height) } } … class UserPreferencesDataStoreImpl( private val context: Context ) { private val Context.dataStore by preferencesDataStore( … ) fun getAge(): Flow<Int> { return context.dataStore.data .map { preferences -> preferences[DataStoreKey. Age] ?: -1 } } … suspend fun setAge(age: Int) { context.dataStore.edit { preferences -> preferences[DataStoreKey. Age] = age } } … } 全てKotlin Courutines (suspend / Flow) に対応させる必要がある。