diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationTemplateViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationTemplateViewWrapper.java index c9dcc5c688ec5..2a47fe00c93bb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationTemplateViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationTemplateViewWrapper.java @@ -227,7 +227,9 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp if (mUiOffloadThread == null) { mUiOffloadThread = Dependency.get(UiOffloadThread.class); } - mUiOffloadThread.submit(() -> pendingIntent.registerCancelListener(listener)); + if (view.isAttachedToWindow()) { + mUiOffloadThread.submit(() -> pendingIntent.registerCancelListener(listener)); + } view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { @Override public void onViewAttachedToWindow(View v) {