Push Notifications doesnt fire method when app is killed

Please provide the following:

  1. SDK Version: 40
  2. Platforms(Android/iOS/web/all): Android
  3. “notification”, “push”, “android”

its works well when app is running or in background but when app is closed or killed the notification doesnt fire the method notificationListener.current or responseListener.current. i saw that was a bug in SDK 38,

import * as Notifications from “expo-notifications”;

Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});

const HomeScreen = (props) => {
const dispatch = useDispatch();
const {navigation} = props || {}
const {navigate} = navigation || {}
const User = useSelector(state => state.auth.User);
const customer = useSelector(state => state.user.customer);
const {name, Url, emails, employee, devices,numbers, avatarUrl} = User || {};
const [isShowingSnackBar, setShowingSnackBar] = useState(false);
const [message, setMessage] = useState(false);
const {name: custormerName, logoUrl} = customer || {};
const [notificationId, setnotificationId] = useState(null);

const [notification, setNotification] = useState(false);
const notificationListener = useRef();
const responseListener = useRef();




//Check notification
useEffect(() => {
    notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
        console.log('entrou notification');
        console.log(notification);
        const {request, date} = notification ||{}
        const {content} = request ||{}
        const {data} = content ||{}
        const {annKey,type} = data ||{}
        console.log(type);
        if(annKey) {
          //  navigation.navigate('Detail', {annKey,  updateFeed: true, onSelect},)
        }
        if(type===0 || type === 1){
            dispatch(renewTokenActionV2(()=>{}));
        }

    });


    responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
        console.log('entrou response');

        const {notification} = response ||{}
        console.log(notification);
        const {request, date} = notification ||{}
        const {content} = request ||{}
        const {data} = content ||{}
        const {annKey, type} = data ||{}


        if(annKey){
           navigation.navigate('Detail', {annKey,  updateFeed: true, onSelect},)
        }

        if(type===0 || type === 1){
            dispatch(renewTokenActionV2(()=>{}));
        }
    });

    return () => {
        Notifications.removeNotificationSubscription(notificationListener);
        Notifications.removeNotificationSubscription(responseListener);
    };
}, []);
1 Like

Hey @tigpalmas2, there is a lot going on with your code snippet. Could you reduce it to just the minimum relevant code and share it as a public repo that we can clone and run without having to copy and paste code?

Cheers,
Adam

Hi @adamjnav thanks for you replay. i did it in GitHub - tigpalmas/testepush. Build a new managed project install expo-notifications. Build android app, install in device correclty but when the app is close and receive a notification should navigate to DetailPage but it doesnt happen. Only when the app is open or in background works fine. Thank you

with legacy Notificatino was working correclty , the new api notification dont.

if you close the app while the cable is connected to the device, it then blocks every notification when the app is closed. However, if you take the cable off the device and close the app, when you send the notification, everything works again, as it should !