-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐛] 🔥 onNotificationOpenedApp() not running and getInitialNotification() not providing data when restoring app state from storage on Android #7976
Comments
hey @haakonrj-dyplink - happy to look into this. Do you have a simple way to verify this behaviour? |
Hi, sorry for the late response, but we wanted to due some more testing, and ask a friend that has more experience than me with this package. Here are two videos. One where a notification opens the app normally from killed state. The other I open the app through a notification after opening a ton of other apps, moving the app state from ram to storage. We have removed any splash screens for these tests. We have tried reproducing the result by limiting the phones resources trough developer options, but have been unsuccessful. Only way we have reproduced the error is by opening apps until the appstate is moved to storage. When doing this the onRestoreInstanceState in MainActivity gets called. NB! while the first video shows navigation to the correct page while the second dont, it is not what we are testing for. To exclude potential error with navigation we are purely looking if messaging().getInitialNotification() gives notification data when opening the app // First video opening fresh. Here the messaging().getInitialNotification() always gives the notification data, and navigates the user to the correct page // Restoring state from storage. This video is cut to reduce length. Just a bunch of app openings. Here the app is opened then put in the background by opening other apps through a script. After opening enough apps the appstate is moved to storage. Then app is opened through the notification. messaging().getInitialNotification() runs but the remoteMessage is null, and navigation does not happen. We belive after much logging and testing by moving the listeners around the app and trying different initiation timeout that this is some kind of race condition. While we never got remoteMessage to contain the data in this situation. We did replicate the same behaviour by changing where we initiated our app by placing the listeners outside of the react native app, by just setting them up directly in index.js. Then when opening the app from a notification while not in background (fresh state) messaging().getInitialNotification() gave null 50% of the time |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
Got a stale warning on this issue. Is this being looked into, or is there something required by me still? |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
@haakonrj-dyplink - hmmm, it seems somewhat convoluted trying to recreate this bug. If you could create some reproducible steps to recreate the bug, I can take a look. My time is limited managing a number of repositories so I really prioritise issues that I can reproduce unfortunately. |
Issue
Describe your issue here
Hi, we are experiencing a problem where opening the app from a push notification do not provide notification data, or trigger the onNotificationOpenenedApp event when app with app-state is restored from storage on Android. I do not mean from memory.
It happens when the app-state has been stopped and lies in memory then moved to storage after phone runs out of ram by opening other apps etc. When opening a push notification when the app is in this state. The app-state is restored from storage, and the onNotificationOpenenedApp does not trigger and getInitialNotification() gives null for the remoteMessage.
In all other scenarios we have no problems with push notifications, it only happens in this rear scenario.
Project Files
build.gradle
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.22"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.google.gms:google-services:4.4.2")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
}
}
apply plugin: "com.facebook.react.rootproject"
Javascript
// User has permissions or provisional permissions
messaging().onNotificationOpenedApp(async (remoteMessage) => {
console.log('Notification opened app:', remoteMessage);
if (remoteMessage?.data?.url) {
notificationQueue.enqueue({ url: remoteMessage.data.url as string });
}
});
// Handle foreground messages
messaging().onMessage(async (remoteMessage) => {
console.log('Foreground message:', remoteMessage);
});
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Doing some handling :)');
});
// Check for notifications that caused the app to open from a terminated state
messaging()
.getInitialNotification()
.then((remoteMessage) => {
console.log('Notification caused app to open from terminated state:', remoteMessage);
if (remoteMessage?.data?.url) {
notificationQueue.enqueue({ url: remoteMessage.data.url as string });
}
});
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:// N/A
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:AndroidManifest.xml
:Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:20.3.0
Firebase
module(s) you're using that has the issue:e.g. Instance ID
TypeScript
?Y
&4.8.4
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: