1313import com .google .firebase .FirebaseApp ;
1414import com .wix .reactnativenotifications .core .AppLifecycleFacade ;
1515import com .wix .reactnativenotifications .core .AppLifecycleFacadeHolder ;
16- import com .wix .reactnativenotifications .core .InitialNotificationHolder ;
1716import com .wix .reactnativenotifications .core .NotificationIntentAdapter ;
1817import com .wix .reactnativenotifications .core .notification .IPushNotification ;
1918import com .wix .reactnativenotifications .core .notification .PushNotification ;
20- import com .wix .reactnativenotifications .core .notification .PushNotificationProps ;
2119import com .wix .reactnativenotifications .core .notificationdrawer .IPushNotificationsDrawer ;
2220import com .wix .reactnativenotifications .core .notificationdrawer .PushNotificationsDrawer ;
2321
@@ -29,8 +27,6 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
2927
3028 private final Application mApplication ;
3129
32- private boolean openedNotifications = false ;
33-
3430 public RNNotificationsPackage (Application application ) {
3531 mApplication = application ;
3632 FirebaseApp .initializeApp (application .getApplicationContext ());
@@ -63,40 +59,28 @@ public void onAppNotVisible() {
6359 public void onActivityCreated (Activity activity , Bundle savedInstanceState ) {
6460 final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer .get (mApplication .getApplicationContext ());
6561 notificationsDrawer .onNewActivity (activity );
66-
67- Intent intent = activity .getIntent ();
68- if (NotificationIntentAdapter .canHandleIntent (intent )) {
69- Bundle notificationData = intent .getExtras ();
70- final IPushNotification pushNotification = PushNotification .get (mApplication .getApplicationContext (), notificationData );
71- if (pushNotification != null ) {
72- pushNotification .onOpened ();
73- }
74- }
7562 }
7663
7764 @ Override
7865 public void onActivityStarted (Activity activity ) {
79-
8066 }
8167
82-
8368 @ Override
8469 public void onActivityResumed (Activity activity ) {
85- if (openedNotifications ) {
86- return ;
87- }
88-
8970 final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer .get (mApplication .getApplicationContext ());
9071 notificationsDrawer .onNewActivity (activity );
9172
9273 Intent intent = activity .getIntent ();
9374 if (NotificationIntentAdapter .canHandleIntent (intent )) {
94- Bundle notificationData = intent .getExtras ();
95- final IPushNotification pushNotification = PushNotification .get (mApplication .getApplicationContext (), notificationData );
96- if (pushNotification != null ) {
97- openedNotifications = true ;
98- pushNotification .onOpened ();
99- }
75+ Context appContext = mApplication .getApplicationContext ();
76+ Bundle notificationData = NotificationIntentAdapter .extractPendingNotificationDataFromIntent (intent );
77+ final IPushNotification pushNotification = PushNotification .get (appContext , notificationData );
78+ if (pushNotification != null ) {
79+ pushNotification .onOpened ();
80+ // Clear the notification intent after handling to prevent duplicate processing
81+ // when the app goes to background and returns
82+ activity .setIntent (new Intent ());
83+ }
10084 }
10185 }
10286
@@ -115,19 +99,4 @@ public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
11599 @ Override
116100 public void onActivityDestroyed (Activity activity ) {
117101 }
118-
119- private void callOnOpenedIfNeed (Activity activity ) {
120- Intent intent = activity .getIntent ();
121- if (NotificationIntentAdapter .canHandleIntent (intent )) {
122- Context appContext = mApplication .getApplicationContext ();
123- Bundle notificationData = NotificationIntentAdapter .extractPendingNotificationDataFromIntent (intent );
124- final IPushNotification pushNotification = PushNotification .get (appContext , notificationData );
125- if (pushNotification != null ) {
126- pushNotification .onOpened ();
127- // Erase notification intent after using it, to avoid looping with the same notification
128- // in case the app is moved to background and opened again
129- activity .setIntent (new Intent ());
130- }
131- }
132- }
133102}
0 commit comments