Android Usage
Use stores in Android apps with Kotlin.
This page shows the recommended path first, then advanced customization APIs.
Easy Path (Recommended)
Use generated Kotlin types with the built-in Gson serializer.
1. Register Store Once
Register your store during app startup (for example in Activity.onCreate when savedInstanceState == null):
registerStoreIfNeeded returns null when the same key is already registered, which keeps registration idempotent across lifecycle re-entries.
2. Retrieve the Typed Store
3. Read, Update, and Subscribe
Advanced Path (Custom Serialization)
Use this when default Gson serialization is not enough (custom formats, compatibility rules, encrypted payloads, etc.).
Option A: Custom Serializer Interface
Option B: Encode/Decode Lambdas
Both advanced options produce the same Store<State> API as the easy path.
API Summary
registerStoreIfNeeded(storeName, initialState)- Easy one-time registration.registerStore(storeName, initialState)- Always creates/registers store.brownieStoreDefinition(...)- Store definition API (default or custom serializer).StoreManager.shared.store<T>(key)- Retrieve typed store by key.Store.set { ... }- Update full typed state.Store.subscribe { ... }and selectorsubscribe(...)- Observe state changes.
