Repository navigation
feat(android): [Part 2] Start a new nav transaction when returning to a nav root - #6482
Open
0xadam-brown wants to merge 2 commits into
Open
0xadam-brown wants to merge 2 commits into
0xadam-brown wants to merge 2 commits into
Conversation
A nav root that regains the nav lease (e.g., when the Activity covering it closes, the user swipes back to its ViewPager2 page, or a dialog over it is dismissed) now gets a new nav transaction for its current destination if its previous one has finished. Before, spans produced on return had no transaction to attach to until the next navigation. StagedNavTransaction keeps the destination's NavTransactionRequest after its transaction finishes or can't start, and starts a new transaction from it on the next publication. The request replaces the NavTransaction handle that recorded writes for replay, and is kept in step with back stack changes below the top via updateNavTransactionRequest.
This was referenced Nov 6, 2026
Contributor
|
📲 Install BuildsAndroid
|
0xadam-brown
marked this pull request as ready for review
November 6, 2026 12:32
0xadam-brown
requested review from
markushi and
runningcode
and removed request for
a team
November 6, 2026 12:32
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
Starts a new Nav3 transaction for the current destination when the user returns to a nav root whose previous transaction has finished. Matches behavior of Nav2 + Compose.
How this PR fixes it
Replaces the one-shot
NavTransactionwith a reusableNavTransactionRequest. The request is kept until the user leaves the destination. When a nav root gets the lease back, it rebinds its unfinished transaction or starts a new one from the request.[1] Quota impact: This PR increases the number of transactions some apps send. Returning to a nav root now starts a new nav transaction if the previous one finished. That includes closing an Activity that covered it, swiping back to a ViewPager2 page, or dismissing a dialog over it. Apps with lots of back-and-forth between nav roots will send more nav transactions than before. (Note: empty transactions aren't charged against user quotas, so only return transactions that have spans attached to them will count, and they're the ones users will want, anyway.)
Note that apps will still send fewer transactions with Nav3 than they do with Nav2 + Compose. Nav2 + Compose starts a new transaction on every resume; this PR starts one only if the resumed nav root's prior transaction finished in the meantime (otherwise the original transaction is re-bound).
[2] Behavior is enabled by default: I haven't bothered creating an opt-in flag b/c Nav3 support is still experimental and isn't widely used; the behavior prior to this fix looks random because it depends on i) whether the Android framework keeps the returned-to Activity or Fragment alive, and ii) how long the user spent on the non-candidate screen; and absent the fix work done upon return (eg, a data refresh when the screen resumes) would be lost.
💡 Motivation and Context
Before, a nav root returned to after its transaction finished got none until its next navigation, so spans produced on return (e.g., by work the nav root resumes) were dropped. This was most visible with ViewPager2 pages and with Activities that were covered for longer than the idle timeout.
addresses: JAVA-823
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
The next PR in the stack stops attributing errors and spans from Activities and ViewPager2 pages without a
SentryNavEffectto the most recently visited nav root.