Skip to content

FeedbackShakeIntegration leaks the first resumed Activity #6685

Closed

Description

@runningcode

LeakCanary reports a destroyed MainActivity retained by the shake-to-report integration in the Android sample app (API 37).

Leak path: Application.mActivityLifecycleCallbacks → FeedbackShakeIntegration.shakeDetector → SentryShakeDetector.sensorManager → SystemSensorManager.mContext → MainActivity (destroyed).

Cause

SentryShakeDetector caches its SensorManager the first time it is initialized. FeedbackShakeIntegration passes the resumed Activity to start(), and Activity.getSystemService(SENSOR_SERVICE) returns a manager created for that Activity, which holds the Activity as its context. The cached manager outlives the Activity, so the Activity can never be collected.

It is timing-dependent: enableOnShake() warms up the detector with the Application on a background executor, which caches a safe manager. The leak only happens when an Activity resumes before that warm-up runs. The caching came in with the off-main-thread init (#5784).

Fix

Resolve the SensorManager from the application context in SentryShakeDetector.init, regardless of which context the caller passes.

Activity

  1. self-assigned this
    on Nov 19, 2026
  2. linear-code commented on Nov 19, 2026

    @linear-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions