Skip to content

Commit 285afde

Browse files
antonisclaude
andcommitted
fix(feedback): restore onFormClose in onActivityDestroyed fallback path
When the dialog's host activity is destroyed and onDismiss doesn't fire, onActivityDestroyed now restores the previous onFormClose callback on global options, preventing a stale wrapper from affecting subsequent non-shake feedback dialogs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0cb8d00 commit 285afde

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class FeedbackShakeIntegration
2828
private volatile @Nullable Activity currentActivity;
2929
private volatile boolean isDialogShowing = false;
3030
private volatile @Nullable Activity dialogActivity;
31+
private @Nullable Runnable previousOnFormClose;
3132

3233
public FeedbackShakeIntegration(final @NotNull Application application) {
3334
this.application = Objects.requireNonNull(application, "Application is required");
@@ -97,6 +98,10 @@ public void onActivityDestroyed(final @NotNull Activity activity) {
9798
if (activity == dialogActivity) {
9899
isDialogShowing = false;
99100
dialogActivity = null;
101+
if (options != null && previousOnFormClose != null) {
102+
options.getFeedbackOptions().setOnFormClose(previousOnFormClose);
103+
}
104+
previousOnFormClose = null;
100105
}
101106
}
102107

@@ -117,11 +122,10 @@ private void startShakeDetection(final @NotNull Activity activity) {
117122
if (isDialogShowing) {
118123
return;
119124
}
120-
final Runnable previousOnFormClose =
121-
options.getFeedbackOptions().getOnFormClose();
122125
try {
123126
isDialogShowing = true;
124127
dialogActivity = active;
128+
previousOnFormClose = options.getFeedbackOptions().getOnFormClose();
125129
options
126130
.getFeedbackOptions()
127131
.setOnFormClose(
@@ -132,12 +136,14 @@ private void startShakeDetection(final @NotNull Activity activity) {
132136
if (previousOnFormClose != null) {
133137
previousOnFormClose.run();
134138
}
139+
previousOnFormClose = null;
135140
});
136141
options.getFeedbackOptions().getDialogHandler().showDialog(null, null);
137142
} catch (Throwable e) {
138143
isDialogShowing = false;
139144
dialogActivity = null;
140145
options.getFeedbackOptions().setOnFormClose(previousOnFormClose);
146+
previousOnFormClose = null;
141147
options
142148
.getLogger()
143149
.log(SentryLevel.ERROR, "Failed to show feedback dialog on shake.", e);

0 commit comments

Comments
 (0)