'react-native-notifications Notification opened when app is opened from app tray (Android only)
I am using react-native-notifications version 4.2.4 on React Native 0.64.1. I have also tried on react-native-notifications version 4.3.1 on React Native 0.67.
Steps
- Hard close the app.
- Open a notification.
getInitialNotification()
is populated. The app will open the first screen, then navigate to a screen with the notification details. - Press the hardware back button twice (at this point the app has been exited)
- Open the app from the app tray.
Expected Result
onNotificationOpened()
event listener is not fired and the first screen of the app is shown
Actual Result
onNotificationOpened()
event listener is fired and step 2 happens.
If I comment out the call to callOnOpenIfNeed()
in onActivityStarted()
in RNNotificationsPackage.java, this only happens the first time after the app is hard closed. I believe that this function is causing the issue to happen and notification.onOpened()
is being called incorrectly as the Intent.getExtras()
should not have the notification object.
See below for reference:
private void callOnOpenedIfNeed(Activity activity) {
Intent intent = activity.getIntent();
if (NotificationIntentAdapter.canHandleIntent(intent)) {
Context appContext = mApplication.getApplicationContext();
Bundle notificationData = NotificationIntentAdapter.cannotHandleTrampolineActivity(appContext) ?
NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras();
final IPushNotification pushNotification = PushNotification.get(appContext, notificationData);
if (pushNotification != null) {
pushNotification.onOpened();
}
}
}
I have seen this on Android versions 9-12.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|