Repository navigation
feat(android): [Part 4] Prefer Activity ui.load transactions over Nav3 transactions - #6484
0xadam-brown wants to merge 4 commits into
Conversation
|
📲 Install BuildsAndroid
|
274e94e to
6460391
Compare
e8905ea to
9ea9424
Compare
…nsactions The Nav3 lease is now also withdrawn when an Activity is created over the leaseholder, not only when it resumes. On API 29+, creation is reported from onActivityPreCreated, before ActivityLifecycleIntegration binds the new Activity's ui.load transaction, so the leaseholder's nav transaction no longer holds the scope's transaction slot and ui.load binds, as with Nav2. Errors and spans from the new Activity's onCreate and onStart are no longer attributed to the leaseholder on any API level. Because ui.load now binds, returning quickly to a nav root while the closed Activity's ui.load is still running would leave the nav root's transaction blocked. The coordinator therefore retries binding the leaseholder's nav transaction once when another Activity is destroyed, within 10s of the blocked attempt. Below API 29, there's no onActivityPreCreated, so the new Activity's ui.load stays unbound as before; this is documented in the package README.
Hold a candidate's host Activity weakly so a candidate that fails to unregister can't keep a destroyed Activity alive, replace the resumedOnly flag with a minimumState parameter, and tidy the README footnotes.
6460391 to
3b26f99
Compare
9ea9424 to
bb73582
Compare
The window for retrying a nav transaction blocked by an Activity's ui.load transaction was measured by subtracting SentryDates from options.dateProvider. That clock is replaceable, falls back to wall-clock time unless both dates carry a nanoTime, and doesn't count while an Android device suspends. Record an io.sentry.time.Deadline when the publication is blocked instead, on the ticker from options.getMonotonicTicker(), which StagedNavTransaction now takes as a constructor parameter so tests can drive it with TestMonotonicTicker. A retry exactly at the end of the 10-second window no longer qualifies.
bb73582 to
688b4a7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 688b4a7. Configure here.
| stagedNavTransaction.publishTo(delegate) | ||
| // Don't retry b/c ui.load retry is only for returns to a nav root, not for navigation | ||
| // within it. | ||
| stagedNavTransaction.publishTo(delegate, canRetry = false) |
There was a problem hiding this comment.
Return navigation cancels ui.load retry
Medium Severity
Returning from a covering Activity arms a one-shot ui.load retry, but a same-lease navigation before that Activity is destroyed cancels it. finishNavTransaction clears blockedPublication, and startNavTransaction then publishes with canRetry = false, so the new destination never re-arms. A Compose LaunchedEffect that navigates after resume (typical for activity results in Nav3) leaves that destination with no bound nav transaction until a later navigation.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 688b4a7. Configure here.
runningcode
left a comment
There was a problem hiding this comment.
Looks good with 1 comment for you to look at!
|
|
||
| /** | ||
| * After [activity] is destroyed, asks the leaseholder to retry publication if an Activity's | ||
| * `ui.load` blocked it. The publisher decides whether the blocker has left and retry is allowed. |
There was a problem hiding this comment.
so my agent tells me that this retry isn't completely necessary.
for example, if you go to Activity B from nav screen A and press back quickly enough, the retry blocks A when it resumes
my clanker says it would simplify the code the remove the retry. ill let you decide!


PR Stack (Nav3 Lifecycle)
📜 Description
When the user opens an Activity from a Nav3 root, that Activity's
ui.loadtransaction is now bound to the scope instead of being blocked by the Nav3 root's nav transaction (API 29+), matching Nav2. A Nav3 transaction blocked by a closing Activity'sui.loadis retried once.ui.loadtransaction†ui.loadbinds in preference to the nav transaction, as it does with Nav2How this PR fixes things
This PR withdraws the lease when a covering Activity is created. On API 29+ this happens in
onActivityPreCreated, which runs beforeActivityLifecycleIntegrationtries to bindui.load, thereby allowing theui.loadtransaction to beat out the nav transaction.Below API 29 there's no
onActivityPreCreated, so creation is reported fromonActivityCreated, meaning the nav transaction beats out theui.loadtransaction.Known gaps
Documented in the package README.
ui.actiontransaction from the gesture that caused the return can still block the nav transaction.ui.load.Addressing the last two would require updating
ActivityLifecycleIntegrationto unbind a finishing Activity'sui.loadwhen it pauses. That'd change behavior for every app and not just users of Nav3, so I haven't included it here. We could follow-up at some point if we care to. Nicely, tackling things in ActivityLifecycleIntegration would have the happy side effect of simplifying the heuristics we have to use here.💡 Motivation and Context
Nav2 lets an Activity's
ui.loadtransaction take precedence, but Nav3 blocked it whenever the Activity was opened from a Nav3 root, so the Activity's auto-instrumented spans went elsewhere. Withdrawing the lease only on resume (#6483) also left the covering Activity'sonCreate/onStartwork attributed to the previous root.addresses: JAVA-785
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Last PR in the stack. Once the stack is merged into the collection branch, squash-merge #6480 into
main.