SerializableCircuitSaver
Returns a CircuitSaver that persists CircuitSaveable types with kotlinx-serialization, encoding them to SavedState via androidx.savedstate.
In 0.35, Android Screen and PopResult implementations must still be Parcelable, even though this saver stores SavedState rather than the Parcelable value. That Android supertype requirement will be removed in a future release.
Screens and results must be @Serializable and registered for polymorphic serialization against the CircuitSaveable base class in configuration's serializersModule:
val saver = SerializableCircuitSaver(
SavedStateConfiguration {
serializersModule = SerializersModule {
polymorphic(CircuitSaveable::class) {
subclass(HomeScreen::class)
subclass(DetailScreen::class)
subclass(DetailResult::class)
}
}
}
)Saving an unregistered type fails with a descriptive error. Restoring an unregistered type, such as after an app update removed a screen, drops that record instead of failing. Pass onRestoreError to observe dropped records, such as for logging.
On JVM and Android, ReflectiveSerializableCircuitSaver from the circuit-serialization-reflect artifact can be used instead to avoid the registration requirement.