fix(splash-screen): defer removeOnPreDrawListener to main looper#2548
Open
FelippoStedile wants to merge 1 commit into
Open
fix(splash-screen): defer removeOnPreDrawListener to main looper#2548FelippoStedile wants to merge 1 commit into
FelippoStedile wants to merge 1 commit into
Conversation
…void stuck splash / crash on Android 12+
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.
fix(splash-screen): defer removeOnPreDrawListener to main looper to avoid stuck splash / crash on Android 12+
Description
Defer the
removeOnPreDrawListener(...)call by posting it to the main looper, so removalruns on a clean pass of the UI thread after the current draw/dispatch cycle has completed.
The view and listener references are captured into locals because
onPreDrawListeneriscleared immediately afterward.
Applied to both Android-12 hide paths:
hide()andhideDialog().Change Type
Rationale / Problems Fixed
On Android 12+ (the
OnPreDrawListener-based splash flow),hide()andhideDialog()call
removeOnPreDrawListener(...)synchronously. When hide is triggered from within thepre-draw dispatch cycle (the common case — the app calls
hide()as soon as content isready), the
ViewTreeObserver's listener list is being mutated while it is still iterating it.This causes one of two failure modes depending on device/OS version:
falseand the splash screenstays on screen permanently — the app appears hung at launch.
IllegalStateException/ concurrent-modification while dispatching pre-draw listeners.Tests or Reproductions
Reproduced a permanently-stuck splash on launch on Android 12/13 when
hide()is calledduring the pre-draw phase; with this change the splash dismisses reliably and no
concurrent-modification exception is thrown. No behavior change on the dialog/legacy path.
Platforms Affected
Notes / Comments
There are three call sites for
removeOnPreDrawListenerin this file. This PR only changesthe two
hidepaths (hide()andhideDialog()), which currently call it synchronously andare the ones that can run during the pre-draw dispatch cycle.
The third call site, in
showWithAndroid12API(), is intentionally left unchanged: its removalalready runs inside a
Handler.postDelayed(...)lambda, so it is not exposed to the sameconcurrent-modification / stuck-splash issue. Wrapping it again would be redundant.