diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index ac0427481..b75ebe4f0 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -63,11 +63,13 @@ protected PushNotification(Context context, Bundle bundle, AppLifecycleFacade ap } @Override - public void onReceived() throws InvalidNotificationException { - if (!mAppLifecycleFacade.isAppVisible()) { + public void onReceived() { + ReactContext reactContext = mAppLifecycleFacade.getRunningReactContext(); + boolean hasActiveCatalystInstance = reactContext != null && reactContext.hasActiveCatalystInstance(); + if (!mAppLifecycleFacade.isAppVisible() || !hasActiveCatalystInstance) { postNotification(null); - notifyReceivedBackgroundToJS(); - } else { + } + if (hasActiveCatalystInstance) { notifyReceivedToJS(); } } @@ -130,17 +132,13 @@ protected void dispatchImmediately() { } protected void dispatchUponVisibility() { - mAppLifecycleFacade.addVisibilityListener(getIntermediateAppVisibilityListener()); + mAppLifecycleFacade.addVisibilityListener(mAppVisibilityListener); // Make the app visible so that we'll dispatch the notification opening when visibility changes to 'true' (see // above listener registration). launchOrResumeApp(); } - protected AppVisibilityListener getIntermediateAppVisibilityListener() { - return mAppVisibilityListener; - } - protected Notification buildNotification(PendingIntent intent) { return getNotificationBuilder(intent).build(); }