Skip to content

🔥 messaging().getInitialNotification() returns null after opening app from a quit state #8493

@Slisandro

Description

@Slisandro

Issue

When opening my app from a FCM notification (while app is quit), messaging().getInitialNotification() always returns null.
Notifications are working fine in background and foreground states.
I already checked common issues:

  • I'm not using react-native-splash-screen (I have a custom animated splash screen with Animated component).

  • I'm not using Notifee.

  • Using a physical Android device.

  • Tried sending notification and data payload.

  • Using the correct setBackgroundMessageHandler inside a useEffect.

  • expo-notifications has been uninstalled.

Still, getInitialNotification() keeps returning null.

Project Files

Click To Expand

package.json:

"dependencies": {
    "@expo/vector-icons": "^14.0.2",
    "@google/generative-ai": "^0.24.0",
    "@react-native-async-storage/async-storage": "^1.24.0",
    "@react-native-firebase/app": "^21.14.0",
    "@react-native-firebase/firestore": "^21.14.0",
    "@react-native-firebase/messaging": "^21.14.0",
    "@react-navigation/native": "^7.0.14",
    "axios": "^1.8.4",
    "expo": "~52.0.40",
    "expo-clipboard": "~7.0.1",
    "expo-constants": "~17.0.8",
    "expo-dev-client": "~5.0.20",
    "expo-font": "~13.0.4",
    "expo-linear-gradient": "^14.0.2",
    "expo-linking": "~7.0.5",
    "expo-router": "~4.0.19",
    "expo-secure-store": "~14.0.1",
    "expo-status-bar": "~2.0.1",
    "firebase": "^11.5.0",
    "firebase-admin": "^13.2.0",
    "formik": "^2.4.6",
    "google-auth-library": "^9.15.1",
    "react": "18.3.1",
    "react-native": "0.76.7",
    "react-native-country-codes-picker": "^2.3.5",
    "react-native-markdown-display": "^7.0.2",
    "react-native-paper": "^5.13.1",
    "react-native-reanimated": "~3.16.1",
    "react-native-safe-area-context": "4.12.0",
    "react-native-screens": "~4.4.0",
    "react-native-webview": "13.12.5",
    "toastify-react-native": "^6.0.0",
    "yup": "^1.6.1"
  } 

app.json:

{
  "expo": {
    "name": "apptest",
    "slug": "apptest",
    "version": "1.0.0",
    "orientation": "portrait",
    "scheme": "myapp",
    "userInterfaceStyle": "automatic",
    "newArchEnabled": true,
    "ios": {
      "supportsTablet": true,
      "googleServicesFile": "./GoogleService-Info.plist",
      "bundleIdentifier": "com.slisandro.apptest"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/icon.png",
        "backgroundColor": "#ffffff"
      },
      "googleServicesFile": "./google-services.json",
      "package": "com.slisandro.apptest"
    },
    "web": {
      "bundler": "metro",
      "output": "static",
      "favicon": "./assets/icon.png"
    },
    "plugins": [
      "expo-router",
      "expo-secure-store",
      "@react-native-firebase/app"
    ],
    "experiments": {
      "typedRoutes": true
    },
    "extra": {
      "router": {
        "origin": false
      },
      "eas": {
        "projectId": "75c14a30-6da9-4007-b857-b886016aa243"
      }
    },
    "owner": "slisandro"
  }
}

eas.json:

{
  "cli": {
    "version": ">= 16.3.1",
    "appVersionSource": "remote"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {
      "developmentClient": false,
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

Field for send test notification:

const sendNotification = async () => {
  const message = {
    token: "",

    notification: {
      title: "Notificación de prueba",
      body: "Esta es una prueba",
    },

    data: {
      screen: "/detail",
      id: "ID_PRODUCT",
    },
  };

  try {
    const response = await admin.messaging().send(message);
    console.log("✅ :", response);
  } catch (error) {
    console.error("❌ :", error);
  }
};

  • Platform that you're experiencing the issue on:
    • Android
  • Are you using TypeScript?
    • Yes & ^5.8.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions