Skip to content

Commit 0b090bc

Browse files
antonisclaude
andcommitted
fix(feedback): scope dialog flag to hosting activity and restore callback on error
- Only reset isDialogShowing in onActivityDestroyed when it's the activity that hosts the dialog, not any unrelated activity. - Restore originalOnFormClose in the catch block when showDialog throws. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 527abb7 commit 0b090bc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public final class ShakeDetectionIntegration
2727
private @Nullable SentryAndroidOptions options;
2828
private volatile @Nullable Activity currentActivity;
2929
private volatile boolean isDialogShowing = false;
30+
private volatile @Nullable Activity dialogActivity;
3031
private @Nullable Runnable originalOnFormClose;
3132

3233
public ShakeDetectionIntegration(final @NotNull Application application) {
@@ -93,10 +94,12 @@ public void onActivitySaveInstanceState(
9394

9495
@Override
9596
public void onActivityDestroyed(final @NotNull Activity activity) {
96-
// Reset dialog flag — the dialog cannot outlive the activity being destroyed,
97-
// so clear the flag to avoid permanently blocking shake-to-feedback
98-
// (e.g. if showDialog silently failed).
99-
isDialogShowing = false;
97+
// Only reset if this is the activity that hosts the dialog — the dialog cannot
98+
// outlive its host activity being destroyed.
99+
if (activity == dialogActivity) {
100+
isDialogShowing = false;
101+
dialogActivity = null;
102+
}
100103
}
101104

102105
private void startShakeDetection(final @NotNull Activity activity) {
@@ -118,11 +121,13 @@ private void startShakeDetection(final @NotNull Activity activity) {
118121
}
119122
try {
120123
isDialogShowing = true;
124+
dialogActivity = active;
121125
options
122126
.getFeedbackOptions()
123127
.setOnFormClose(
124128
() -> {
125129
isDialogShowing = false;
130+
dialogActivity = null;
126131
options.getFeedbackOptions().setOnFormClose(originalOnFormClose);
127132
if (originalOnFormClose != null) {
128133
originalOnFormClose.run();
@@ -131,6 +136,8 @@ private void startShakeDetection(final @NotNull Activity activity) {
131136
options.getFeedbackOptions().getDialogHandler().showDialog(null, null);
132137
} catch (Throwable e) {
133138
isDialogShowing = false;
139+
dialogActivity = null;
140+
options.getFeedbackOptions().setOnFormClose(originalOnFormClose);
134141
options
135142
.getLogger()
136143
.log(SentryLevel.ERROR, "Failed to show feedback dialog on shake.", e);

0 commit comments

Comments
 (0)