From 7170a263ee9223f9cee0fc144aed83096ea83982 Mon Sep 17 00:00:00 2001 From: danielel Date: Sat, 26 Feb 2022 23:28:35 +0200 Subject: [PATCH] fix initial notification from killed --- .../RNNotificationsPackage.java | 30 +++++++++---------- .../core/notification/PushNotification.java | 1 - 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java index e3f177a50..9f568b8f2 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java @@ -61,25 +61,13 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) { final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(mApplication.getApplicationContext()); notificationsDrawer.onNewActivity(activity); - Intent intent = activity.getIntent(); - if (NotificationIntentAdapter.canHandleIntent(intent)) { - Bundle notificationData = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R ? - NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras(); - final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData); - if (pushNotification != null) { - pushNotification.onOpened(); - } - } + callOnOpenedIfNeed(activity); } @Override public void onActivityStarted(Activity activity) { - Bundle bundle = activity.getIntent().getExtras(); - if (bundle != null) { - PushNotificationProps props = new PushNotificationProps(bundle); - if (props.isFirebaseBackgroundPayload()) { - InitialNotificationHolder.getInstance().set(props); - } + if (InitialNotificationHolder.getInstance().get() == null) { + callOnOpenedIfNeed(activity); } } @@ -102,4 +90,16 @@ public void onActivitySaveInstanceState(Activity activity, Bundle outState) { @Override public void onActivityDestroyed(Activity activity) { } + + private void callOnOpenedIfNeed(Activity activity) { + Intent intent = activity.getIntent(); + if (NotificationIntentAdapter.canHandleIntent(intent)) { + Bundle notificationData = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R ? + NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras(); + final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData); + if (pushNotification != null) { + pushNotification.onOpened(); + } + } + } } 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 d24eccfe4..dedc98ad6 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 @@ -17,7 +17,6 @@ import com.wix.reactnativenotifications.core.InitialNotificationHolder; import com.wix.reactnativenotifications.core.JsIOHelper; import com.wix.reactnativenotifications.core.NotificationIntentAdapter; -import com.wix.reactnativenotifications.core.ProxyService; import static com.wix.reactnativenotifications.Defs.NOTIFICATION_OPENED_EVENT_NAME; import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME;