Fix back gesture unresponsive state and fragment stack corruption#1936
Open
rybnikov wants to merge 1 commit intoDrKLO:masterfrom
Open
Fix back gesture unresponsive state and fragment stack corruption#1936rybnikov wants to merge 1 commit intoDrKLO:masterfrom
rybnikov wants to merge 1 commit intoDrKLO:masterfrom
Conversation
This was referenced Feb 23, 2026
e323805 to
1e637cd
Compare
scutuatua-crypto
approved these changes
Feb 25, 2026
Two independent issues that cause navigation to break: 1. Animation state flags (transitionAnimationInProgress, animationInProgress, predictiveInput, etc.) can persist across activity lifecycle events, permanently blocking back presses, touch events, and fragment navigation. Added forceResetAnimationState() called from onResume()/onPause() to clear stale animation state. Callbacks are discarded rather than executed to avoid modifying the fragment stack during lifecycle transitions. 2. LaunchActivity.onDestroy() unconditionally calls clearFragments() and destroys global singletons (PhotoViewer, Theme, MediaController, etc.). When a new activity instance exists (share intents, foldable config changes, activity recreation after finish()), the stale instance's onDestroy tears down UI and fragments used by the active instance. Guarded both clearFragments() and global singleton teardown with instance == this check. Also fixed SDK 33 back callback unregistration checking wrong variable (onBackAnimationCallback vs onBackInvokedCallback).
1e637cd to
ba264be
Compare
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.
Summary
Fixes two independent issues that cause navigation to break, particularly on foldable devices and when sharing content from external apps.
1. Animation state stuck across activity lifecycle
Navigation in
ActionBarLayoutis gated by several boolean flags:transitionAnimationInProgress,animationInProgress,predictiveInput,predictiveBackInProgress, andstartedTracking. When any of these aretrue,onBackPressed(),presentFragment(), and touch events are blocked.These flags can get stuck when the activity goes through
onPause()/onResume()while an animation is in progress (e.g., user switches apps mid-gesture, foldable device triggers configuration change during transition). The original code had a commented-out attempt to handle this inonResume()— it calledonCloseAnimationEnd()/onOpenAnimationEnd(), but those execute callbacks that modify the fragment stack (closeLastFragmentInternalRemoveOld), which is unsafe during lifecycle events.Fix: Added
forceResetAnimationState()that resets all animation flags and discards pending callbacks instead of executing them. Called from bothonResume()andonPause().2. Stale activity instance destroys shared state
LaunchActivityuses static collections (mainFragmentsStack,layerFragmentsStack,rightFragmentsStack) shared across all instances. Multiple instances can coexist when:finish()(common with back gesture on foldables)When
onDestroy()runs on a stale instance, it unconditionally:clearFragments(), emptying the static fragment stacks used by the active instanceThis leaves the active instance with empty navigation stacks and destroyed UI components — back button silently does nothing, screens can't be opened, viewers are broken.
Fix: Guard both
clearFragments()and global singleton teardown withinstance == this, so only the currently active instance performs cleanup. Also fixed SDK 33 back callback unregistration checking the wrong variable (onBackAnimationCallbackinstead ofonBackInvokedCallback).Files changed
ActionBarLayout.java— addforceResetAnimationState(), call fromonResume()/onPause()LaunchActivity.java— guardclearFragments()and global UI teardown inonDestroy()withinstance == this; fix SDK 33 callback variableTest plan