Repository navigation
feat(android): Multiple LifecycleOwner support for Nav3 - #6301
Open
0xadam-brown wants to merge 1 commit into
Open
0xadam-brown wants to merge 1 commit into
0xadam-brown wants to merge 1 commit into
Conversation
Contributor
|
📲 Install BuildsAndroid
|
This was referenced Oct 20, 2026
0xadam-brown
marked this pull request as ready for review
October 20, 2026 15:30
5 of 9 tasks
0xadam-brown
force-pushed
the
feat/sentry-nav-effect-lifecycle
branch
from
October 21, 2026 11:27
c2667a5 to
c464ea3
Compare
0xadam-brown
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Oct 21, 2026
Update the Android Navigation page to reflect the changes in the PR stack rooted at [sentry-java #6301](getsentry/sentry-java#6301), which introduces support for Nav3 setups involving multiple NavDisplay <> SentryNavEffect pairs. Supported vs non-supported setups are now listed explicitly.
0xadam-brown
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Oct 21, 2026
Update the Android Navigation page to reflect the changes in the PR stack rooted at [sentry-java #6301](getsentry/sentry-java#6301), which introduces support for Nav3 setups involving multiple NavDisplay <> SentryNavEffect pairs. Supported vs non-supported setups are now listed explicitly.
0xadam-brown
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Oct 21, 2026
Update the Android Navigation page to reflect the changes in the PR stack rooted at [sentry-java #6301](getsentry/sentry-java#6301), which introduces support for Nav3 setups involving multiple NavDisplay <> SentryNavEffect pairs. Supported vs non-supported setups are now listed explicitly.
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.
PR Stack (Nav3 Lifecycle)
📜 Description
PR stack lets us support Nav3 for app architectures involving multiple
NavDisplay<>SentryNavEffectpairs, subject to certain limitations (see the "Still not supported" list below). Prior to this stack, we assumed only oneNavDisplay<>SentryNavEffectpair would be active at a time.Supported
NavDisplay<>SentryNavEffectpair.NavDisplay<>SentryNavEffectpair.NavDisplay<>SentryNavEffectpair.ViewPager2whose pages are Fragments, each with its ownNavDisplay<>SentryNavEffectpair.NavDisplaythat stays visible beneath aDialogFragmentor translucent Activity with its ownNavDisplay.Before this PR stack, we only supported (1) and its functional equivalents.
Still not supported
NavDisplay<>SentryNavEffectpairs in the same Activity or Fragment.NavDisplay<>SentryNavEffectpairs in the same Activity or Fragment.SentryNavEffectinstances in multiple Activities or Fragments that users can interact with at the same time, such as two Activities from the same app in multi-resume mode.SentryNavEffectinstances in pages or tabs that share their host's lifecycle, such as ComposeHorizontalPagerpages,ViewPager2pages that aren't Fragments, or tabs kept in the composition at once. (Those pages or tabs share oneLifecycleOwner, so at most one can callSentryNavEffect.)🔎 The basic approach
Supporting the new setups listed above requires coordinating multiple, simultaneously active
SentryNavEffects and their updates to the current (mutable + shared)IScopevended byIScopes.Like all forms of state management around Android lifecycles + shared mutable state, that code isn't exactly simple. To keep things manageable (and easy to update!), I've been careful to sequester all coordination logic to the new
.navigation3.lifecyclepackage.The basic idea was to replace the
IScopesinstance ourBackStackObserveralready talked to with a smarter version (NavScopes) that could toggle between the shared underlying scope and a per-instance staged version, depending on whether the observer was associated with the incoming or outgoing SentryNavEffect. (Under the hood, NavScopes relies on lease-based ownership to decide who can update the scope, which is overseen by the newNavLeaseCoordinator.)That^^ let me keep updates to SentryNavEffect, BackStackObserver, etc. to a minimum, and it makes it easy to swap out our implementation in the future, should we ever hide our IScopes API behind a
LocalSentrySpan-esque system (or any of a number of other possibilities) 🎉 .💡 Motivation and Context
Lets us support the multi-Activity and multi-Fragment app setups listed above. Those setups are common, and without the changes here, spans and nav state would be incorrect when transitioning between Activities or Fragments.
That's worrisome, because Activity / Fragment startup logic is a common source of bugs and crashes, so properly attributing Sentry data there is especially worthwhile.
addresses: JAVA-785
💚 How did you test it?
Each stack branch is formatted, API-dumped, built, and tested independently before its PR is opened.
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
main.#skip-changelog