Google は、黒人コミュニティに対する人種平等の促進に取り組んでいます。取り組みを見る

androidx.datastore.preferences

Top-level functions summary

SharedPreferencesMigration<Preferences>
SharedPreferencesMigration(produceSharedPreferences: () -> SharedPreferences, keysToMigrate: Set<String>? = MIGRATE_ALL_KEYS)

Creates a SharedPreferencesMigration for DataStore.

SharedPreferencesMigration<Preferences>
SharedPreferencesMigration(context: Context, sharedPreferencesName: String, keysToMigrate: Set<String>? = MIGRATE_ALL_KEYS)

Creates a SharedPreferencesMigration for DataStore.

ReadOnlyProperty<Context, DataStore<Preferences>>
preferencesDataStore(name: String, corruptionHandler: ReplaceFileCorruptionHandler<Preferences>? = null, migrations: List<DataMigration<Preferences>> = listOf(), scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()))

Creates a property delegate for a single process DataStore.

Top-level functions

SharedPreferencesMigration

@JvmOverloads fun SharedPreferencesMigration(
    produceSharedPreferences: () -> SharedPreferences,
    keysToMigrate: Set<String>? = MIGRATE_ALL_KEYS
): SharedPreferencesMigration<Preferences>

Creates a SharedPreferencesMigration for DataStore.

Note: This migration only supports the basic SharedPreferences types: boolean, float, int, long, string and string set. If the result of getAll contains other types, they will be ignored.

Parameters
produceSharedPreferences: () -> SharedPreferences Should return the instance of SharedPreferences to migrate from.
keysToMigrate: Set<String>? = MIGRATE_ALL_KEYS The list of keys to migrate. The keys will be mapped to datastore.Preferences with their same values. If the key is already present in the new Preferences, the key will not be migrated again. If the key is not present in the SharedPreferences it will not be migrated. If keysToMigrate is not set, all keys will be migrated from the existing SharedPreferences.

SharedPreferencesMigration

@JvmOverloads fun SharedPreferencesMigration(
    context: Context,
    sharedPreferencesName: String,
    keysToMigrate: Set<String>? = MIGRATE_ALL_KEYS
): SharedPreferencesMigration<Preferences>

Creates a SharedPreferencesMigration for DataStore.

If the SharedPreferences is empty once the migration completes, this migration will attempt to delete it.

Parameters
context: Context Context used for getting SharedPreferences.
sharedPreferencesName: String The name of the SharedPreferences.
keysToMigrate: Set<String>? = MIGRATE_ALL_KEYS The list of keys to migrate. The keys will be mapped to datastore.Preferences with their same values. If the key is already present in the new Preferences, the key will not be migrated again. If the key is not present in the SharedPreferences it will not be migrated. If keysToMigrate is not set, all keys will be migrated from the existing SharedPreferences.

preferencesDataStore

@JvmOverloads fun preferencesDataStore(
    name: String,
    corruptionHandler: ReplaceFileCorruptionHandler<Preferences>? = null,
    migrations: List<DataMigration<Preferences>> = listOf(),
    scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
): ReadOnlyProperty<Context, DataStore<Preferences>>

Creates a p