Skip to content

ref(android): Support Nav3 for multi-Activity applications - #6229

Draft
0xadam-brown wants to merge 1 commit into
mainfrom
ref/sentry-nav-effect-lifecycle
Draft

0xadam-brown wants to merge 1 commit into
mainfrom
ref/sentry-nav-effect-lifecycle

Conversation

@0xadam-brown

@0xadam-brown 0xadam-brown commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

📜 Description

PR allows separate SentryNavEffect instances to overlap during Activity or Fragment transitions without stale cleanup clobbering the active observer.**

Like all forms of state management around Android lifecycles, this code isn't exactly simple. To keep things manageable (and easy to update!), I've been careful to sequester all state management to the NavScopes file. The basic idea was simply to replace the IScopes instance BackStackObserver already talked to with a smarter version 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.

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) 🎉 .

See the NavScopes KDoc for more details, including some helpful diagrams.

💡 Motivation and Context

Lets us support multi-Activity or multi-Fragment apps, where each Activity / Fragment has its own SentryNavEffect <> NavDisplay pair. That setup is common, and without the changes here, spans and nav state would be incorrect for the initial destination in each newly-launched Activity.

That's worrisome, because Activity startup logic is a common source of bugs / crashes, so properly attributing Sentry data there is especially worthwhile.

addresses: JAVA-274

💚 How did you test it?

  • Unit tests
  • Had my clanker use the new Nav3 sample app tab introduced in this PR to verify that nav data was interleaved and garbled when switching between Activity <> SentryNavEffect pairs prior to this PR, and fixed after.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

  • Update sentry-docs to match the updates here.

@sentry

sentry Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.60.0 (1) release

⚙️ sentry-android Build Distribution Settings

@0xadam-brown 0xadam-brown mentioned this pull request Oct 7, 2026
5 of 9 tasks
@0xadam-brown
0xadam-brown force-pushed the ref/sentry-nav-effect-lifecycle branch 5 times, most recently from 72119f1 to 54924cc Compare October 13, 2026 11:44
@0xadam-brown 0xadam-brown changed the title ref(android): Support updates to nav state across multiple SentryNavEffect instances ref(android): Support Nav3 for multi-Activity applications Oct 13, 2026
@0xadam-brown
0xadam-brown force-pushed the ref/sentry-nav-effect-lifecycle branch from 54924cc to b1ebe22 Compare October 13, 2026 12:01
Introduce Nav3 support for multi-Activity applications by managing shared SentryNavEffect state so that multiple instances can overlap during Activity transitions without interfering with one another.

Basic approach was to replace the IScopes instance that BackStackObserver already talks to with a a smarter version that can toggle between the shared underlying scope and a per-instance staged version, depending on whether the observer is associated with the incoming our outgoing SentryNavEffect.

Doing so let's us keep modifications to SentryNavEffect, BackStackObserver, etc. to a minimum, and makes it easy to swap out our implementation in the future, should we eventually hide our IScopes API behind a LocalSentrySpan-esque system (or any of a number of other possibilities).
@0xadam-brown
0xadam-brown force-pushed the ref/sentry-nav-effect-lifecycle branch from b1ebe22 to 06c7bd8 Compare October 13, 2026 12:02

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant