DataStoreDelegateKt
public final class DataStoreDelegateKt
Summary
Public methods |
|
|---|---|
static final @NonNull ReadOnlyProperty<@NonNull Context, @NonNull DataStore<@NonNull T>> |
<T extends Object> dataStore(Creates a property delegate for a single process DataStore. |
static final @NonNull ReadOnlyProperty<@NonNull Context, @NonNull DataStore<@NonNull T>> |
@RequiresApi(value = 24)Creates a property delegate for a single process DataStore to be used in direct boot. |
Public methods
dataStore
public static final @NonNull ReadOnlyProperty<@NonNull Context, @NonNull DataStore<@NonNull T>> <T extends Object> dataStore(
@NonNull String fileName,
@NonNull Serializer<@NonNull T> serializer,
ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler,
@NonNull Function1<@NonNull Context, @NonNull List<@NonNull DataMigration<@NonNull T>>> produceMigrations,
@NonNull CoroutineScope scope
)
Creates a property delegate for a single process DataStore. This should only be called once in a file (at the top level), and all usages of the DataStore should use a reference the same Instance. The receiver type for the property delegate must be an instance of Context.
This should only be used from a single application in a single classloader in a single process.
Example usage:
val Context.myDataStore by dataStore("filename", serializer)
class SomeClass(val context: Context) {
suspend fun update() = context.myDataStore.updateData {...}
}
| Parameters | |
|---|---|
@NonNull String fileName |
the filename relative to Context.applicationContext.filesDir that DataStore acts on. The File is obtained from |
@NonNull Serializer<@NonNull T> serializer |
The serializer for |
ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler |
The corruptionHandler is invoked if DataStore encounters a |
@NonNull Function1<@NonNull Context, @NonNull List<@NonNull DataMigration<@NonNull T>>> produceMigrations |
produce the migrations. The ApplicationContext is passed in to these callbacks as a parameter. DataMigrations 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.) |
@NonNull CoroutineScope scope |
The scope in which IO operations and transform functions will execute. |
deviceProtectedDataStore
@RequiresApi(value = 24)
public static final @NonNull ReadOnlyProperty<@NonNull Context, @NonNull DataStore<@NonNull T>> <T extends Object> deviceProtectedDataStore(
@NonNull String fileName,
@NonNull Serializer<@NonNull T> serializer,
ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler,
@NonNull Function1<@NonNull Context, @NonNull List<@NonNull DataMigration<@NonNull T>>> produceMigrations,
@NonNull CoroutineScope scope
)
Creates a property delegate for a single process DataStore to be used in direct boot.
| Parameters | |
|---|---|
@NonNull String fileName |
the filename relative to Context.applicationContext.filesDir that DataStore acts on. The File is obtained from |
@NonNull Serializer<@NonNull T> serializer |
The serializer for |
ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler |
The corruptionHandler is invoked if DataStore encounters a |
@NonNull Function1<@NonNull Context, @NonNull List<@NonNull DataMigration<@NonNull T>>> produceMigrations |
produce the migrations. The ApplicationContext is passed in to these callbacks as a parameter. DataMigrations 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.) |
@NonNull CoroutineScope scope |
The scope in which IO operations and transform functions will execute. |