SerializableCircuitSaver

fun SerializableCircuitSaver(configuration: SavedStateConfiguration = SavedStateConfiguration.DEFAULT, onRestoreError: (Throwable) -> Unit = {}): CircuitSaver(source)

Returns a CircuitSaver that persists CircuitSaveable types with kotlinx serialization. It encodes them to SavedState with androidx.savedstate.

Android Screen and PopResult implementations must still be Parcelable. This saver stores SavedState instead of the Parcelable value. A future release will remove the Parcelable requirement.

Screens and results must have a kotlinx serializer and be registered for polymorphic serialization against the CircuitSaveable base class. Use Serializable for manual registration or CircuitSerializable with Circuit code generation. Manual registrations belong in configuration's serializersModule. Registrations against CircuitSaveable are also used for nested properties declared as Screen or PopResult:

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 returns null, allowing the navigation owner to drop that record. Pass onRestoreError to observe restoration failures.

On JVM and Android, ReflectiveSerializableCircuitSaver from the circuit-serialization-reflect artifact can be used instead to avoid the registration requirement.


fun SerializableCircuitSaver(registrations: Iterable<CircuitSerializerRegistration>, configuration: SavedStateConfiguration = SavedStateConfiguration.DEFAULT, onRestoreError: (Throwable) -> Unit = {}): CircuitSaver(source)

Returns a CircuitSaver that persists the screens and pop results supplied by registrations.

The registrations are added to configuration's existing serializers module. The other configuration options are preserved. Conflicting serializer registrations fail when the saver is created.