Skip to content

[pull] androidx-main from androidx:androidx-main#1310

Merged
pull[bot] merged 3 commits into
MaxMood96:androidx-mainfrom
androidx:androidx-main
Jul 26, 2026
Merged

[pull] androidx-main from androidx:androidx-main#1310
pull[bot] merged 3 commits into
MaxMood96:androidx-mainfrom
androidx:androidx-main

Conversation

@pull

@pull pull Bot commented Jul 26, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

- Inlined the `SavedStateHandleAttacher` logic by having `SavedStateHandleSupportController` implement `LifecycleEventObserver` directly, simplifying observer registration in `enableSavedStateHandles()`.
- Inlined `createSavedStateHandle` helper function into the public `CreationExtras.createSavedStateHandle()` extension.
- Nested the `ViewModel` class inside `SavedStateHandleSupportController` as a private `StateHolder` class, completely encapsulating it.
- Simplified caching logic inside `createSavedStateHandle()` using Kotlin's `getOrPut` mapping function.
- Used Kotlin class delegation (`by`) inside `SavedStateHandleSupportController` to delegate to `SavedStateRegistryOwner` and `ViewModelStoreOwner`.
- Removed all private file/package-level extension properties.

Test: existing passes
Relnote: N/A
Change-Id: I8169df0252e337544a39bd085ee3f28eb298bcbb
Consolidate the multiplatform SavedStateHandleSupportController and the legacy Android SavedStateHandleController into a unified SavedStateHandleController class in commonMain.

Previously, Android and multiplatform targets managed SavedStateHandles differently. The legacy Android system used a reflection-based OnRecreation hook and addCloseable tags on ViewModels to reattach handles on recreation. That recreation hook crashed if the SavedStateRegistryOwner did not implement ViewModelStoreOwner.

We consolidated this into the multiplatform StateHolder ViewModel system, which was already in place for CreationExtras. Because ViewModels survive configuration changes, we no longer need custom closeable tags to retain handles.

To maintain backwards compatibility, the legacy factories (SavedStateViewModelFactory and AbstractSavedStateViewModelFactory) continue to register the reflection-based OnRecreation hook. The modern pathway (enableSavedStateHandles and createSavedStateHandle) completely bypasses it.

Since retrieving the StateHolder requires a ViewModelStoreOwner, the owner parameter must implement this interface. We now enforce this at instantiation time (failing fast) instead of crashing later during recreation.

RelNote: """`SavedStateViewModelFactory` and `AbstractSavedStateViewModelFactory` now fail-fast immediately if the provided `SavedStateRegistryOwner` does not implement `ViewModelStoreOwner`, preventing delayed crashes during component recreation."""

Test: SavedStateFactoryTest, SavedStateHandleSupportTest
Change-Id: Icf31744863b188ad68aad7c253a8cdfc30f33ba1
* changes:
  Unify SavedStateHandleController
  Refactor SavedStateHandleSupport
@pull pull Bot locked and limited conversation to collaborators Jul 26, 2026
@pull pull Bot added the ⤵️ pull label Jul 26, 2026
@pull
pull Bot merged commit 07a12dd into MaxMood96:androidx-main Jul 26, 2026
1 check was pending
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant