Shared Preferences
The Preferences Explorer lets you view and edit SharedPreferences and Jetpack DataStore values directly from the Snapbug Desktop app. Changes are applied to the device in real time.
Features
- Auto-detection of SharedPreferences files
- Manual registration for custom preference sources
- DataStore support via dedicated dependency
- Custom implementations via
SnapbugPreferenceinterface
Auto-Detection
On Android, Snapbug automatically detects all SharedPreferences files used by your app. No additional setup is required.
Manual Registration
To register a specific SharedPreferences instance:
val prefs = context.getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
SnapbugSharedPreference.register("my_prefs", prefs)DataStore Support
To inspect Jetpack DataStore preferences, add the DataStore dependency:
dependencies {
debugImplementation("ai.snapbug:snapbug-datastores:1.0.0")
releaseImplementation("ai.snapbug:snapbug-datastores-no-op:1.0.0")
}Then register your DataStore instance:
SnapbugDatastorePreference.register("settings", dataStore)DataStore values are displayed as key-value pairs, the same as SharedPreferences. Proto DataStore fields are serialized to their string representation.
Custom Implementations
For non-standard preference stores (e.g., encrypted preferences, MMKV), implement the SnapbugPreference interface:
class MyCustomPreference : SnapbugPreference {
override val name: String = "encrypted_prefs"
override fun getAll(): Map<String, Any?> {
// Return all key-value pairs from your custom store
return myEncryptedStore.getAll()
}
override fun put(key: String, value: Any?) {
// Write a value to your custom store
myEncryptedStore.put(key, value)
}
override fun remove(key: String) {
// Remove a value from your custom store
myEncryptedStore.remove(key)
}
}Register your custom implementation:
SnapbugSharedPreference.register(MyCustomPreference())Editing preference values from the Desktop app modifies them directly on the device. Changes take effect immediately.