Skip to content

Commit 43b5ebc

Browse files
antonisclaude
andcommitted
fix(feedback): capture onFormClose at shake time instead of registration
Capture the current onFormClose callback just before showing the dialog rather than caching it during register(). This ensures callbacks set by the user after SDK init are preserved across shake-triggered dialogs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1fd4f5b commit 43b5ebc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ 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 originalOnFormClose;
3231

3332
public FeedbackShakeIntegration(final @NotNull Application application) {
3433
this.application = Objects.requireNonNull(application, "Application is required");
@@ -43,7 +42,6 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions
4342
}
4443

4544
addIntegrationToSdkVersion("FeedbackShake");
46-
originalOnFormClose = this.options.getFeedbackOptions().getOnFormClose();
4745
application.registerActivityLifecycleCallbacks(this);
4846
options.getLogger().log(SentryLevel.DEBUG, "FeedbackShakeIntegration installed.");
4947

@@ -119,6 +117,8 @@ private void startShakeDetection(final @NotNull Activity activity) {
119117
if (isDialogShowing) {
120118
return;
121119
}
120+
final Runnable previousOnFormClose =
121+
options.getFeedbackOptions().getOnFormClose();
122122
try {
123123
isDialogShowing = true;
124124
dialogActivity = active;
@@ -128,16 +128,16 @@ private void startShakeDetection(final @NotNull Activity activity) {
128128
() -> {
129129
isDialogShowing = false;
130130
dialogActivity = null;
131-
options.getFeedbackOptions().setOnFormClose(originalOnFormClose);
132-
if (originalOnFormClose != null) {
133-
originalOnFormClose.run();
131+
options.getFeedbackOptions().setOnFormClose(previousOnFormClose);
132+
if (previousOnFormClose != null) {
133+
previousOnFormClose.run();
134134
}
135135
});
136136
options.getFeedbackOptions().getDialogHandler().showDialog(null, null);
137137
} catch (Throwable e) {
138138
isDialogShowing = false;
139139
dialogActivity = null;
140-
options.getFeedbackOptions().setOnFormClose(originalOnFormClose);
140+
options.getFeedbackOptions().setOnFormClose(previousOnFormClose);
141141
options
142142
.getLogger()
143143
.log(SentryLevel.ERROR, "Failed to show feedback dialog on shake.", e);

0 commit comments

Comments
 (0)