Fix: Settings title stuck when backing out of sub-menus#2387
Merged
Conversation
On Android 16 with predictive back, childFragmentManager's back-stack-changed listener fires while the new fragment is already RESUMED but backStackEntryCount has not yet been decremented. The old implementation read the count during the callback and ended up re-applying the previous sub-screen's title over the restored index content. Drive the toolbar from FragmentLifecycleCallbacks.onFragmentResumed instead, and derive title from the child fragment's own arguments rather than a parallel screens list. No back-stack-count lookups means no stale-value race. Closes #2386
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Fixed a bug on Android 16 where the Settings header stayed on a sub-page's name (e.g. "CorpseFinder") after backing out to the main Settings list with the system back button. The page content returned correctly — only the title stayed stuck. The toolbar's own back arrow was not affected.
Technical Context
RESUMEDbeforechildFragmentManager.backStackEntryCounthas been decremented. BothonBackStackChangedandonFragmentResumedsee a stale count.screens: ArrayList<Screen>mirroring the back stack and updated the toolbar fromaddOnBackStackChangedListener. On Android 16 the listener fired once with the pre-pop count and never fired again after the actual pop, so the toolbar stayed on the sub-page's title.FragmentLifecycleCallbacksand, on each childonFragmentResumed, read the title directly from the fragment's own arguments (BKEY_SCREEN_TITLE). The root fragment has no such arg, so it falls back to the default "Settings". No back-stack-count reads in the hot path — no more stale-value race.SettingsFragment.kt. Shared infra (PreferenceFragment2,ToolbarHost) is untouched —SqueezerSettingsFragmentusesPreferenceFragment2as a top-level nav route without aToolbarHostparent, and this fix shouldn't leak into that path.Closes #2386