Expo Push Notification Navigate

  1. SDK Version: 40
  2. Platform: Android

Hey guys, when I click at response Expo Push it’s open a new index.js and navigating to screen and after some seconds it return to my home screen, it’s required put expo push notification responseListener at root of project? on app.js? why it’s open a new index.js tab? My project is like this:

App.js:

<SocketContext.Provider value={socket}>
        <AuthProvider>
                <ChannelProvider>
                  <MessageProvider>
                    <Wrapper />  -> my sendpushnotifcation and responseListener.current
                  </MessageProvider>
                </ChannelProvider>
        </AuthProvider>
    </SocketContext.Provider>
 useEffect(() => {
    registerForPushNotificationsAsync().then((token) =>
      setExpoPushToken(token)
    );

    responseListener.current = Notifications.addNotificationResponseReceivedListener(
      (response) => {
        console.log("RESPONSE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + response);

        var data = response.notification.request.content.data;

        console.log(
          "info_request D-ATAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAA---AAAAAAAAA-AAAAAAAAA"
        );

        navigate("Room");

        return () => subscription.remove();
      }

      // }
    );

    notificationListener.current = Notifications.addNotificationReceivedListener(
      (notification) => {
        setNotification(notification);
      }
    );

    return () => {
      Notifications.removeNotificationSubscription(notificationListener);
      Notifications.removeNotificationSubscription(responseListener);
    };
  }, []);
  async function sendPushNotification(
    pushToken,
    roomID,
    favor,
    respondent,

  ) {
    // console.log(favor);
    console.log(
      "push sent!!!!!!!!!!!!" + pushToken,
      roomID,
      favor,
      respondent,
    
    );

    const messageRequisitioner = {
      to: pushToken,
      sound: "default",
      title: "Nova notificacione",
      body: "[Foto]",
      data: {
        roomID: roomID,
        requisitioner: state.currentUser,
        requisitioner_token: expoPushToken,
        favor: favor, //filtered footprint
      },
    };

    const messageRespondent = {
      to: pushToken,
      sound: "default",
      title: "Nova Informação em tempo real",
      body: "Uma foto similar ksks",
      data: {
        roomID: roomID,
        respondent: respondent,
        requisitioner_token: expoPushToken,
        favor: favor, //filtered footprint
      },
    };

    await fetch("https://exp.host/--/api/v2/push/send", {
      method: "POST",
      headers: {
        Accept: "application/json",
        "Accept-encoding": "gzip, deflate",
        "Content-Type": "application/json",
      },
      body: respondent
        ? JSON.stringify(messageRespondent)
        : JSON.stringify(messageRequisitioner),
    });
  }

it’s a good idea to add your listeners as early as possible, so yes. Otherwise I’m not sure I understand the issue here- when you receive a notification, it forces your app back to the homescreen? I would remove parts from your addNotificationResponseReceivedListener until you find the root cause

I already tried just with the standard script available at documentation. when I click at notification I use my response to get some details at response.notification.request.content.data and navigate to screen. the currently behaviour is:

1- I send the push
2- the push comes very well
3- I click at push and it’s opening a new index.js
4- after open new index.js in some seconds go to my screen normally
5- I send the push for myself in this new index opened
6- I click at notification and open normally in this new index. it’s not opening a new index and I not need wait seconds I go directly

so it’s openening just one new index , it can causing because I’m testing with myself in the same device? I need transfer to my App.js obligatorily?

I’m using a async function at addNotificationResponseReceivedListener to get asyncstorage

What do you mean when you say that the push is opening a new index.js?