Skip to content

fix(feedback): Stop shake detection from leaking the first resumed Activity - #6686

Merged
runningcode merged 2 commits into
mainfrom
no/fix-shake-detector-activity-leak
Nov 19, 2026
Merged

runningcode merged 2 commits into
mainfrom
no/fix-shake-detector-activity-leak

Conversation

@runningcode

Copy link
Copy Markdown
Contributor

📜 Description

SentryShakeDetector now gets its SensorManager from the application context, whichever context the caller passes in.

💡 Motivation and Context

LeakCanary found a destroyed MainActivity in the Android sample, held through FeedbackShakeIntegration.shakeDetector → SentryShakeDetector.sensorManager → SystemSensorManager.mContext.

The detector caches its SensorManager the first time it initializes. An Activity's getSystemService(SENSOR_SERVICE) returns a manager tied to that Activity. So when an Activity resumed before the background warm-up from #5784 ran, the app-lifetime integration held that Activity forever.

  • resolves: JAVA-847

💚 How did you test it?

Added a unit test that starts the detector with an Activity-like context.

📝 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.

🤖 Generated with Claude Code

…tivity

SentryShakeDetector caches its SensorManager the first time it initializes.
When an Activity resumed before the background warm-up ran, that manager
came from the Activity, and an Activity's SensorManager keeps a reference
to it. The long-lived FeedbackShakeIntegration then held the destroyed
Activity for the rest of the process.

Always resolve the SensorManager from the application context.

Fixes JAVA-847

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 19, 2026

Copy link
Copy Markdown

JAVA-847

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit aea3d1b.

Main concerns: reach.

This label is a hint for reviewers, not an approval.

@runningcode
runningcode marked this pull request as ready for review November 19, 2026 16:58
@runningcode
runningcode requested review from a team and adinauer as code owners November 19, 2026 16:58
@runningcode
runningcode requested review from markushi and romtsn and removed request for a team November 19, 2026 16:58
@sentry

sentry Bot commented Nov 19, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 19, 2026

@markushi markushi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

@runningcode
runningcode merged commit 3406bbb into main Nov 19, 2026
49 checks passed
@runningcode
runningcode deleted the no/fix-shake-detector-activity-leak branch November 19, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants