fix(android): Always remove FirstDrawDoneListener after the first draw - #6152
Draft
runningcode wants to merge 2 commits into
Draft
runningcode wants to merge 2 commits into
runningcode wants to merge 2 commits into
Conversation
The listener was removed from an OnGlobalLayoutListener, which only runs if a layout pass follows the draw. On a static screen it stayed registered and ran on every frame, retaining its callback. Post the removal to the main thread instead so it always happens. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
📲 Install BuildsAndroid
|
This branch has not been deployed
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.
📜 Description
FirstDrawDoneListenernow removes itself by posting the removal to the main thread. Before, it waited for the next global layout.💡 Motivation and Context
You can't remove an
OnDrawListenerfrom insideonDraw(API 26+ throws). So the listener registered anOnGlobalLayoutListenerand removed itself from there. But a draw isn't always followed by a layout pass. On a static screen, the listener stayed registered and ran on every frame (as a no-op), and it kept its callback reachable. That callback capturesActivityLifecycleIntegrationand the ttid/ttfd spans.ActivityLifecycleIntegrationregisters a new listener on everyonActivityResumed, so these could pile up on the decor view until the next layout.It isn't a memory leak: everything is only reachable from the decor view's
ViewTreeObserverand dies with the activity. The fix makes the removal happen every time and drops the extra layout listener.💚 How did you test it?
Updated
FirstDrawDoneListenerTest: the listener is now removed afteronDrawwithout any layout pass.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Consider registering only once per activity in
ActivityLifecycleIntegration.onActivityResumed, instead of on every resume.🤖 Generated with Claude Code