Skip to content

Commit 0cc2f3b

Browse files
antonisclaude
andcommitted
fix(feedback): prevent stacking multiple feedback dialogs on repeated shakes
Track dialog visibility with an isDialogShowing flag that is set before showing and cleared via the onFormClose callback when the dialog is dismissed. Double-checked on both sensor and UI threads to avoid races. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d13da1b commit 0cc2f3b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/ShakeDetectionIntegration.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public final class ShakeDetectionIntegration
2626
private @Nullable SentryShakeDetector shakeDetector;
2727
private @Nullable SentryAndroidOptions options;
2828
private volatile @Nullable Activity currentActivity;
29+
private volatile boolean isDialogShowing = false;
2930

3031
public ShakeDetectionIntegration(final @NotNull Application application) {
3132
this.application = Objects.requireNonNull(application, "Application is required");
@@ -102,12 +103,28 @@ private void startShakeDetection(final @NotNull Activity activity) {
102103
activity,
103104
() -> {
104105
final Activity active = currentActivity;
105-
if (active != null && options != null) {
106+
if (active != null && options != null && !isDialogShowing) {
106107
active.runOnUiThread(
107108
() -> {
109+
if (isDialogShowing) {
110+
return;
111+
}
108112
try {
113+
isDialogShowing = true;
114+
final Runnable previousOnFormClose =
115+
options.getFeedbackOptions().getOnFormClose();
116+
options
117+
.getFeedbackOptions()
118+
.setOnFormClose(
119+
() -> {
120+
isDialogShowing = false;
121+
if (previousOnFormClose != null) {
122+
previousOnFormClose.run();
123+
}
124+
});
109125
options.getFeedbackOptions().getDialogHandler().showDialog(null, null);
110126
} catch (Throwable e) {
127+
isDialogShowing = false;
111128
options
112129
.getLogger()
113130
.log(SentryLevel.ERROR, "Failed to show feedback dialog on shake.", e);

0 commit comments

Comments
 (0)