Skip to content

Commit d6f3bdd

Browse files
committed
docs(android): Lifecycle support for Android Nav3 integration
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.
1 parent f1d092b commit d6f3bdd

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

  • docs/platforms/android/integrations/navigation

‎docs/platforms/android/integrations/navigation/index.mdx‎

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ SentryAndroid.init(this) { options ->
384384

385385
Navigation 3 support is available in `sentry-android-navigation3` `8.60.0` and later.
386386

387-
See the [Limitations](#limitations) section below for additional restrictions.
387+
See [Supported Setups](#supported-setups) and [Limitations](#limitations) for setup restrictions.
388388

389389
</Alert>
390390

@@ -406,6 +406,8 @@ See [Customize Nav3 Options](#customize-nav3-options) to learn how to modify tho
406406

407407
Install the Android SDK and add the `sentry-android-navigation3` library:
408408

409+
At runtime, this integration requires Compose UI 1.7 or later, or `lifecycle-runtime-compose` 2.8.3 or later.
410+
409411
```groovy {filename:build.gradle}
410412
dependencies {
411413
implementation 'io.sentry:sentry-android:{{@inject packages.version('sentry.java.android', '8.60.0') }}'
@@ -469,12 +471,6 @@ Values returned from `BackStackEntryMapper` are **not** scrubbed by the Sentry S
469471

470472
</Alert>
471473

472-
<Alert>
473-
474-
Multiple, simultaneously active `SentryNavEffect` instances writing to the same [Sentry scope](https://docs.sentry.io/platforms/android/enriching-events/scopes/) are **_not_** supported. Violating this restriction can result in duplicated or interleaved data and undefined transaction behavior.
475-
476-
</Alert>
477-
478474
### Customize Nav3 Options
479475

480476
Use `SentryNavOptions` to disable breadcrumbs or transactions, or to limit how much of the back stack Sentry stores with captured events.
@@ -634,13 +630,41 @@ val backStackItemMapper = BackStackEntryMapper<NavKey> { entry ->
634630
}
635631
```
636632

633+
### Supported Setups
634+
635+
The setups below require `sentry-android-navigation3` 8.63.0 or later. Earlier versions support only one active `SentryNavEffect` per Sentry scope.
636+
637+
`SentryNavEffect` is compatible with most, but not all, Nav3 setups. Each effect uses the lifecycle of its nearest `LocalLifecycleOwner` to decide when it can write to Sentry's [shared scope](/platforms/android/enriching-events/scopes/), and compatibility between effects depends on how those lifecycle owners interact. Incompatible effects won't crash, but they can generate stale navigation data, produce interleaved breadcrumbs, or interfere with each other's transactions.
638+
639+
<Alert>
640+
641+
All supported setups below assume that each `SentryNavEffect` is called in the same composable as the `NavDisplay` it observes, and that the effect is called before it.
642+
643+
They also assume that `SentryNavEffect` is **_not_** called from content rendered by `NavDisplay`, such as a `NavEntry`, `NavEntryDecorator`, or `Scene`. `SentryNavEffect` needs the lifecycle of the Activity or Fragment hosting your `NavDisplay`, rather than the navigation-scoped lifecycle `NavDisplay` provides to its content.
644+
645+
</Alert>
646+
647+
**Supported:**
648+
649+
- A single-Activity app with one `NavDisplay` and `SentryNavEffect` pair.
650+
- A multi-Activity app where each Activity has its own `NavDisplay` and `SentryNavEffect` pair.
651+
- A multi-Fragment app where each Fragment has its own `NavDisplay` and `SentryNavEffect` pair, and the host Activity or Activities have none of their own.
652+
- A `ViewPager2` whose pages are Fragments, each with its own `NavDisplay` and `SentryNavEffect` pair.
653+
- An Activity or Fragment with its own `NavDisplay` and `SentryNavEffect` pair that stays visible beneath a `DialogFragment` or translucent Activity with its own pair.
654+
655+
**Not supported:**
656+
657+
- Side-by-side `NavDisplay` and `SentryNavEffect` pairs in the same Activity or Fragment.
658+
- Nested `NavDisplay` and `SentryNavEffect` pairs in the same Activity or Fragment. If you nest `NavDisplay` instances, call `SentryNavEffect` only for the outermost one.
659+
- `SentryNavEffect` instances in multiple Activities or Fragments that users can interact with at the same time, such as an Activity and hosted Fragments where the Activity and Fragments each have their own `NavDisplay` and `SentryNavEffect` pairs, or two Activities from the same app in [multi-resume mode](https://developer.android.com/develop/ui/views/layout/support-multi-window-mode).
660+
- `SentryNavEffect` instances in pages or tabs that share their host's lifecycle, such as Compose `HorizontalPager` pages, `ViewPager2` pages that aren't Fragments, or tabs that are all kept in the composition. Those pages or tabs share one `LifecycleOwner`, so at most one can call `SentryNavEffect`.
661+
637662
### Limitations
638663

639664
`SentryNavEffect` treats the top entry in your back stack as the current screen. That works well for most Nav3 setups, but it means that `SentryNavEffect` does **_not_**:
640665

641666
- understand the concept of Nav3 [Scenes](https://developer.android.com/guide/navigation/navigation-3/scenes) or multi-pane layouts
642-
- track multiple back stacks
643-
- permit multiple, simultaneously active `SentryNavEffect` instances
667+
- track multiple back stacks with one `SentryNavEffect` instance
644668
- make special accommodations for [predictive back](https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture) gestures (e.g., spans produced by predictively rendered composables may appear under the current destination's transaction)
645669

646670
## Navigation 2 and Navigation 3 Interoperability

0 commit comments

Comments
 (0)