Google is committed to advancing racial equity for Black communities. See how.


object PreferenceDataStoreFactory
   ↳ androidx.datastore.preferences.PreferenceDataStoreFactory

Public factory for creating PreferenceDataStore instances.


Public methods
create(produceFile: () -> File, corruptionHandler: ReplaceFileCorruptionHandler<Preferences>? = null, migrations: List<DataMigration<Preferences>> = listOf(), scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()))

Create an instance of SingleProcessDataStore.

Public methods


fun create(
    produceFile: () -> File,
    corruptionHandler: ReplaceFileCorruptionHandler<Preferences>? = null,
    migrations: List<DataMigration<Preferences>> = listOf(),
    scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
): DataStore<Preferences>

Create an instance of SingleProcessDataStore. The user is responsible for ensuring that there is never more than one instance of SingleProcessDataStore acting on a file at a time.

produceFile: () -> File Function which returns the file that the new DataStore will act on. The function must return the same path every time. No two instances of PreferenceDataStore should act on the same file at the same time. The file must have the extension preferences_pb.
corruptionHandler: ReplaceFileCorruptionHandler<Preferences>? = null The corruptionHandler is invoked if DataStore encounters a CorruptionException when attempting to read data. CorruptionExceptions are thrown by serializers when data cannot be de-serialized.
migrations: List<DataMigration<Preferences>> = listOf() are run before any access to data can occur. Each producer and migration may be run more than once whether or not it already succeeded (potentially because another migration failed or a write to disk failed.)
scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()) The scope in which IO operations and transform functions will execute.