Repository navigation
fix(android): [Part 3] Stop attributing Nav3 data to screens without a SentryNavEffect #6483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0xadam-brown
wants to merge
4
commits into
feat/nav3-lifecycle-2-return-transactions
Choose a base branch
from
fix/nav3-lifecycle-3-lease-withdrawal
base: feat/nav3-lifecycle-2-return-transactions
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
31bbc88
fix(android): Stop attributing Nav3 data to Activities and pages withโฆ
0xadam-brown 8e3ba19
changelog
0xadam-brown fefb607
ref(android): Fix comment wrapping in NavLeaseCoordinator
0xadam-brown 3b26f99
fix(android): Don't hand the Nav3 lease to a sibling nav root while iโฆ
0xadam-brown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
...navigation3/src/main/kotlin/io/sentry/compose/navigation3/lifecycle/NavActivityWatcher.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package io.sentry.compose.navigation3.lifecycle | ||
|
|
||
| import android.app.Activity | ||
| import android.app.Application | ||
| import android.app.Application.ActivityLifecycleCallbacks | ||
| import android.os.Bundle | ||
|
|
||
| /** | ||
| * Watches every Activity of the host application and reports the Activity lifecycle events that | ||
| * [NavLeaseCoordinator] acts on. | ||
| * | ||
| * - [onActivityResumed] is called when any Activity resumes, including Activities without a | ||
| * `SentryNavEffect`. | ||
| * | ||
| * **Lifetime** | ||
| * | ||
| * The callbacks are registered at most once per watcher and never unregistered. Like | ||
| * `defaultNavLeaseCoordinator`, which owns the watcher used in practice, they're meant to live as | ||
| * long as the process. | ||
| */ | ||
| internal class NavActivityWatcher(private val onActivityResumed: (activity: Activity) -> Unit) { | ||
|
|
||
| private var isWatching = false | ||
|
|
||
| /** Starts watching the Activities of [application]. Does nothing if already watching. */ | ||
| fun watch(application: Application) { | ||
| if (isWatching) { | ||
| return | ||
| } | ||
| isWatching = true | ||
| application.registerActivityLifecycleCallbacks(Callbacks()) | ||
| } | ||
|
|
||
| private inner class Callbacks : ActivityLifecycleCallbacks { | ||
|
|
||
| override fun onActivityResumed(activity: Activity) { | ||
| this@NavActivityWatcher.onActivityResumed(activity) | ||
| } | ||
|
|
||
| override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit | ||
|
|
||
| override fun onActivityStarted(activity: Activity) = Unit | ||
|
|
||
| override fun onActivityPaused(activity: Activity) = Unit | ||
|
|
||
| override fun onActivityStopped(activity: Activity) = Unit | ||
|
|
||
| override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit | ||
|
|
||
| override fun onActivityDestroyed(activity: Activity) = Unit | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Candidate strongly retains host Activity
Medium Severity
Candidate.hostActivitykeeps a strongActivity, and the process-lifetime coordinator holds thatCandidateincandidatesuntildispose().dispose()reachescandidates.remove()only throughconfigureScope, which can throw before the callback runs, so theActivity(and its views) can stay reachable after destruction.Additional Locations (2)
sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/lifecycle/NavLeaseCoordinator.kt#L87-L90sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/lifecycle/NavLeaseCoordinator.kt#L440-L454Triggered by learned rule: Nav3 lease handoff: no sweep; stage without lease
Reviewed by Cursor Bugbot for commit 3b26f99. Configure here.