question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[unimodules][android][notifications] Event listener can miss `emit()` calls made soon after app launch

See original GitHub issue

šŸ› Bug Report

Summary of Issue

If you call Notifications.addResponseReceivedListener in useEffect for example, the listener will not be triggered when opening an app from a completely killed state via a notification. This can also be demonstrated by adding a timeout to componentDidMount as shown here. Without 1 second timeout- events come through; with 1 second timeout- event’s do not come through.

I should note that the emit method is getting called in this case.

Environment - output of expo diagnostics & the platform(s) you’re targeting

Reproducible Demo

https://snack.expo.io/@charliecruzan/push-notifications

Steps to Reproduce

Need to run the app as a published experience or standalone app (or bare debug build) to see the behavior. Press ā€œshow notificationā€ and kill the app, tap the notification, observe that response listener isn’t triggered.

Workaround

The workaround (and possibly long-term solution) is to add the listener outside of any component, then it works as expected (presumably bc of how much sooner it’s getting called?). I changed the docs to suggest this so fewer people run into this issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:101 (24 by maintainers)

github_iconTop GitHub Comments

21reactions
ozertycommented, Oct 1, 2020

Hi @cruzach, Works when app is in background, but not when the app is killed. The issue still persist on Android with both SDK 38 and SDK 39 in a managed workflow. I try to move out addNotificationResponseReceivedListener outside of my component as suggested, but it doesn’t work.

Thanks

6reactions
Guilhemfuelcommented, Oct 27, 2021

@MrIceman @Guilhemfuel Just use the useLastNotificationResponse hook

It doesn’t work either on background and killed. The response will be null…

Read more comments on GitHub >

github_iconTop Results From Across the Web

addEventListener("click",...) firing immediately - Stack Overflow
When you are binding event you are calling the function document.getElementById("tooltip-link1").addEventListener("click",displayTooltip(2));.
Read more >
Input events overview - Android Developers
An event listener is an interface in the View class that contains a single callback method. These methods will be called by the...
Read more >
EventTarget.removeEventListener() - Web APIs | MDN
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.
Read more >
Using Events Emitted from Your Application during End-to ...
In this blog post I will show how to start using web app events in your end-to-end tests with minimal effort. Oh, and...
Read more >
Events | Node.js v19.3.0 Documentation
emit() method allows an arbitrary set of arguments to be passed to the listener functions. Keep in mind that when an ordinary listener...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found