SharedPreferencesStorage

class SharedPreferencesStorage(context: Context, prefsName: String = "dev.bloc.hydrated") : HydratedStorage

HydratedStorage backed by SharedPreferences.

State bytes are Base64-encoded before writing so they survive the string-only SharedPreferences API without corruption.

Create once and assign to HydratedBloc.storage at app startup, before any HydratedBlocs are instantiated:

class App : Application() {
override fun onCreate() {
super.onCreate()
HydratedBloc.storage = SharedPreferencesStorage(this)
BlocObserver.shared = AppBlocObserver()
}
}

The SharedPreferences file is named "dev.bloc.hydrated" by default. Override prefsName to use a custom file name (e.g. for migration or testing).

Constructors

Link copied to clipboard
constructor(context: Context, prefsName: String = "dev.bloc.hydrated")

Functions

Link copied to clipboard
open override fun clear()

Removes all entries managed by this storage.

Link copied to clipboard
open override fun delete(key: String)

Removes the entry for key. No-op if the key does not exist.

Link copied to clipboard
open override fun read(key: String): ByteArray?

Returns the raw bytes stored under key, or null if absent.

Link copied to clipboard
open override fun write(key: String, value: ByteArray)

Persists value under key, overwriting any previous entry.