Peter
06/19/2026, 9:36 AMPeter
06/19/2026, 9:41 AMnavController.navigate {
popUpTo("X") {
saveState = true
}
}efemoney
06/19/2026, 2:06 PMpop operation that clears the current (-ly indexed) screen along with any forward history from that point.Peter
06/19/2026, 2:10 PMNavEntryDecoratorefemoney
06/19/2026, 2:15 PMrememberDecoratedNavEntries (using the strategy I mentioned above for instance), their saved state will be managed by the default SavedStateDecoratorStylianos Gakis
06/20/2026, 7:51 AMSaveableStateHolder
Here is our custom one https://github.com/HedvigInsurance/android/blob/f632b03001a2946caad772dbf1bb02a2ea3e42cf/app/navigation/navigation-compose/src/androidMain/kotlin/com/hedvig/android/navigation/compose/RetainedSaveableStateHolderNavEntryDecorator.kt#L29-L69 which does not remove the state from some entries conditionally.
Similarly, you can adjust your own decorator and add your own sort of tracking to conditionally not remove the state from items that leave your backstack, depending on your requirements.efemoney
06/20/2026, 8:32 AMrememberDecoratedNavEntries will be a target for any NavDecorators.
You can then additionally filter out any entries you dont want as part of your scene state or scene calculation.
Below is my example of screens in bottom tab navigation.Stylianos Gakis
06/20/2026, 8:54 AMStylianos Gakis
06/20/2026, 8:56 AMefemoney
06/20/2026, 9:26 AM(open app)
[A,b,c,d] --------backstack-------- A
(open screen B)
[a,B,c,d] --------backstack-------- A,B
(open screen D)
[a,b,c,D] --------backstack-------- A,D
(open screen E)
[a,b,c,d] -> E --------backstack-------- A,D,E
In the example, the app starts with tabbed screen with options A,B,C,D and A (which is the home screen) as visible screen.
When creating the entries to pass to rememberDecoratedNavEntries(), I mark everything except the currently visible screen & the home screen as "_hidden"_.
For step 1 ----- B, C & D are marked as hidden because A is both the current visible and the home.
I then pass A,B,C,D to rememberDecoratedNavEntries() meaning all keys are decorated and their state will be saved/restored.
And after filtering, only A will remain on the final list.
For step 2 ----- when user navigates to B, A is home screen & B is currently visible, so only C & D are marked as hidden.
I still pass A,B,C,D to rememberDecoratedNavEntries() meaning the state for all keys is still maintained.
this time, A, B will be in the final list.
For step 3 ----- same thing but this time B & C are marked as hidden so that the final list after filtering is A,D.
Because all entries are passed to rememberDecoratedNavEntries() , again their saved state is maintained.
For step 4 ----- when user navigates to a key that is not part of the tabs, that creates a new node.
My data structure is a list of "_nodes"_ where each node is either a tabbed node OR a standalone node.
In this final case, I'll have a list of 2 nodes:
• Tabbed{A,B,C,D}
• Standalone{E}
I flat map these nodes to get the list of keys passed to rememberDecoratedNavEntries() (result: A,B,C,D,E), internally during this transform, I am marking irrelevant-to-final-backstack entries as hidden
and then filter the resulting entries to remove hidden entries (result: A,D,E) so that what goes to my scene state is already the proper size and in order