Notifications listener not triggering when app is killed on Android

Info:

  1. SDK Version: 39
  2. Platforms: Android
  3. Standalone app

This used to be a problem on SDK 38 but fixed (partially for me, only iOS) with SDK 39.

When the app is killed and the user opens it by tapping a push Notifications.addNotificationResponseReceivedListener does not respond.
This happens only on Android. I already tried to move the listener out of all components but still no lack.

Anyone else facing the same issue?
Thanks!

Hi,
Expo cannot handle push notifications if the app is not active.
On the Limitations page they state:

you cannot handle push notifications in the background. This is a work in progress.

You would have to eject for that.

I was doing just that on both Platforms but suddenly since SDK 38 I am having issues.
I cannot find that statement in the page you sent me. By the way, I am not handling something in the background, but actually trying to handle something once the App is open (by tapping a push).

It’s mentioned in the The SDK doesn't support all types of background code execution section.
So the app is open or is still active in the background when you tap on the notification? Or was the app inactive before and the notification triggers the app to open?
Did you specify "android": { "useNextNotificationsApi": true, ...} in the app.json?

Did you specify "android": { "useNextNotificationsApi": true, ...} in the app.json?

Yes, I did. It was working on SDK 37, it began having troubles with the new expo-notifications API in SDK 38 on both Platforms, and SDK 39 fixed only iOS (for me).

For me using this code in the App.js works just fine

React.useEffect(() => {
        const subscriber = Notifications.addNotificationResponseReceivedListener(handleRemoteNotification);

        return () => {
            if (subscriber) {
                subscriber.remove();
            }
        };
    }, []);

This only works if the app is active or was previously active/ is in the background and was not terminated.
If the app is was not started (or was killed) somewhen before you tap the notification it will not trigger my handleRemoteNotification function and only start the app. However this never worked on the previous SDKs for me and I’m quite certain that expo is not capable yet of doing this.

The weird thing is that it was always doing that for me, even now with iOS… not on Android :(((

I’m sorry that I can’t help you then. But if you get it to work somehow please let me know cause I would love to have my notification handled when they were tapped in backgroudn :smiley:

You can see here https://forums.expo.io/t/expo-notification-not-working-when-app-is-closed/45216/3, for example, that it is meant to work. It is great to redirect users to a specific screen when they tap on the push notification, even if the app is killed.

Have you read this github thread? This appears to still be an issue for Android but there are some reports of successful fixes on that thread.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.