Why rememberSaveable Inputs Can Fail After an Android Restore
Brief
A theme change recreated the Activity, and a RevenueCat paywall restored a video URI computed for the previous theme. The cause was that rememberSaveable does not save or validate its inputs across restoration.
The bug and SDK fix
- In SDK 10.21.0, the paywall could briefly show a fallback image before playing the old theme’s video.
- Fix #4219, released in 10.21.1, replaced rememberSaveable(videoUrls.url) with remember(videoUrls), since the URI is a synchronous cache lookup that can be recomputed.
Choosing state restoration behavior
- Use remember(input) for values that can be recomputed; it resets when the input changes but does not survive Activity recreation.
- For state that must survive restoration and reset when its input changes, save the input alongside the value with a Saver, or use key(input) to give each input its own saved slot.
- SaveableStateProvider also gives each input a separate saved scope; unlike resetting to a fresh value, key() and SaveableStateProvider can restore an earlier value when returning to that input.
Generated by AI from the original article. Check the source for full details.