Skip to content

Commit 849087c

Browse files
romtsnclaude
andcommitted
fix(screenshot): Wrap runOnUiThread in try-catch to handle destroyed activity race condition
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent deedc16 commit 849087c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ private boolean isMaskingEnabled() {
156156
final AtomicReference<ViewHierarchyNode> result = new AtomicReference<>(null);
157157
final CountDownLatch latch = new CountDownLatch(1);
158158

159-
activity.runOnUiThread(
160-
() -> {
161-
try {
162-
result.set(buildViewHierarchy(activity));
163-
} finally {
164-
latch.countDown();
165-
}
166-
});
167-
168159
try {
160+
activity.runOnUiThread(
161+
() -> {
162+
try {
163+
result.set(buildViewHierarchy(activity));
164+
} finally {
165+
latch.countDown();
166+
}
167+
});
168+
169169
if (!latch.await(MASKING_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
170170
options
171171
.getLogger()

0 commit comments

Comments
 (0)