You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the OneSignal SDK to handle notifications in my React Native mobile app, compatible with both iOS and Android. Currently, I'm encountering an issue while running my app in development mode via the Metro Bundler: the foregroundWillDisplay event listener function fails to trigger when a notification is received on the Android Emulator.
Upon inspecting the OneSignal database (OneSignal.db) using Android Studio's App Inspection feature, I observed that it correctly stores all sent messages. However, the foregroundWillDisplay event only sporadically fires within my app.
Although I sought a resolution by referring to the troubleshooting guide at this link, it doesn't address the specific issue I'm facing: the app receives notifications and the package stores them, yet the event listener remains inactive.
A section in the troubleshooting guide mentions a "Foreground Notification Received Event" but the linked documentation at this page does not elaborate on it. This discrepancy raises questions about the documentation's accuracy and currency.
Suspecting a threading problem, I inspected the code despite my limited Java proficiency. By inserting log statements into the onWillDisplay function here, the issue seemingly resolved itself. Remarkably, the addition of these logs consistently rectified the problem. Although I conducted about 10 tests, both successful and unsuccessful outcomes were reproducible.
It's common for logging to resolve threading issues as it alters code execution. Consequently, I adjusted the synchronized(){} block and present the modified function below. With this alteration, the notification handling consistently functions as expected:
While I lack expertise in Java development and the inner workings of this package, I hope the maintainer can investigate this fix and provide insights on its validity.
Steps to reproduce?
Follow the documentation from the website regarding setting up OneSignal SDK for ReactNative. Add a listener as described above. Then start your emulator and try to log something from your event listeners. They will only be randomly called. Tested with Android Emulator.
What did you expect to happen?
See the main description above.
React Native OneSignal SDK version
5.0.6
Which platform(s) are affected?
iOS
Android
Relevant log output
No response
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
samsnori
changed the title
[Bug]: Possibly threading issue with willDisplay on Android + documentations clarification
[Bug]: Possibly threading issue with willDisplay on Android + documentatios clarification
Mar 23, 2024
samsnori
changed the title
[Bug]: Possibly threading issue with willDisplay on Android + documentatios clarification
[Bug]: Possibly threading issue with willDisplay on Android + documentation clarification
Mar 23, 2024
Hi @samsnori the notification can show on foreground, but the listener isn't triggered, how to fix it? thank you
"react-native": "0.61.5",
"react-native-onesignal": "^5.2.4",
What happened?
I'm using the OneSignal SDK to handle notifications in my React Native mobile app, compatible with both iOS and Android. Currently, I'm encountering an issue while running my app in development mode via the Metro Bundler: the
foregroundWillDisplay
event listener function fails to trigger when a notification is received on the Android Emulator.Upon inspecting the OneSignal database (
OneSignal.db
) using Android Studio's App Inspection feature, I observed that it correctly stores all sent messages. However, theforegroundWillDisplay
event only sporadically fires within my app.Although I sought a resolution by referring to the troubleshooting guide at this link, it doesn't address the specific issue I'm facing: the app receives notifications and the package stores them, yet the event listener remains inactive.
A section in the troubleshooting guide mentions a "Foreground Notification Received Event" but the linked documentation at this page does not elaborate on it. This discrepancy raises questions about the documentation's accuracy and currency.
Suspecting a threading problem, I inspected the code despite my limited Java proficiency. By inserting log statements into the
onWillDisplay
function here, the issue seemingly resolved itself. Remarkably, the addition of these logs consistently rectified the problem. Although I conducted about 10 tests, both successful and unsuccessful outcomes were reproducible.It's common for logging to resolve threading issues as it alters code execution. Consequently, I adjusted the
synchronized(){}
block and present the modified function below. With this alteration, the notification handling consistently functions as expected:While I lack expertise in Java development and the inner workings of this package, I hope the maintainer can investigate this fix and provide insights on its validity.
Steps to reproduce?
What did you expect to happen?
See the main description above.
React Native OneSignal SDK version
5.0.6
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: