Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android + Open Notification Crash : AssertionError: Tried to start a task on a react context that has already been destroyed #1156

Closed
mohammad-goldast opened this issue Dec 8, 2024 · 1 comment

Comments

@mohammad-goldast
Copy link

Hi,
Today, I installed the latest version of notifee and wanted to use it instead of RN-Push-Notification.
Everything works on IOS like a charm but on Android, I am facing an issue with opening my app by tapping on a notification.

Native Error:

com.ifsguide.app.stagingjava.lang.AssertionError: Tried to start a task on a react context that has already been destroyed
at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:XX)
at com.facebook.react.jstasks.HeadlessJsTaskContext.startTask(HeadlessJsTaskContext.java:XX)
at com.facebook.react.jstasks.HeadlessJsTaskContext.startTask(HeadlessJsTaskContext.java:XX)
at io.invertase.notifee.NotifeeReactUtils.lambda$startHeadlessTask$(NotifeeReactUtils.java:XX)
at io.invertase.notifee.NotifeeReactUtils$$ExternalSyntheticLambda.call(XX$$SyntheticClass:)
at io.invertase.notifee.NotifeeReactUtils$$$ExternalSyntheticLambda.run(XX$$SyntheticClass:)
at android.os.Handler.handleCallback(Handler.java:XX)
at android.os.Handler.dispatchMessage(Handler.java:XX)
at android.os.Looper.loopOnce(Looper.java:XX)
at android.os.Looper.loop(Looper.java:XX)
at android.app.ActivityThread.main(ActivityThread.java:XX)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:XX)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:XX)

Packages info:

"@notifee/react-native": "^9.1.3",
"react-native": "0.76.3",
"@react-native-firebase/analytics": "^21.6.1",
"@react-native-firebase/app": "^21.6.1",
"@react-native-firebase/auth": "^21.6.1",
"@react-native-firebase/database": "^21.6.1",
"@react-native-firebase/firestore": "^21.6.1",
"@react-native-firebase/functions": "^21.6.1",
"@react-native-firebase/messaging": "^21.6.1",
"@react-native-firebase/remote-config": "^21.6.1",
"@react-native-firebase/storage": "^21.6.1",
"firebase": "^11.0.2",

Project info:

  OS: macOS 15.1.1
  CPU: (8) x64 Apple M1
  Memory: 37.37 MB / 8.00 GB
  Shell:
    version: 3.5.1
    path: /opt/homebrew/bin/fish
Binaries:
  Node:
    version: 22.11.0
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.0
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.11.18.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 23.0.1
    path: /opt/homebrew/opt/openjdk/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.3
    wanted: 0.76.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Here is my index.js file :

import '@react-native-firebase/app';
import 'react-native-url-polyfill/auto';
import React from 'react';


import {AppRegistry, Platform, LogBox} from 'react-native';
import {name as appName} from './app.json';

import notifee from '@notifee/react-native';
import {firebase} from '@react-native-firebase/messaging';
import firestore from '@react-native-firebase/firestore';
import auth from '@react-native-firebase/auth';
import remoteConfig from '@react-native-firebase/remote-config';
import storage from '@react-native-firebase/storage';
import functions from '@react-native-firebase/functions';

import Router from './src/navigation/Router';
import Headless from './src/navigation/Headless';

import {pushNotifHelper} from './src/utility/helper/pushNotifHelper';
import {analytics} from './src/utility/helper/analyticsHelper';
import {logger} from './src/utility/helper/functionHelper';


notifee.onBackgroundEvent(async (event) => {
  console.log('event', event);
});

firebase.messaging().setBackgroundMessageHandler(async (message) => {
  const {title, body} = message.notification;

  analytics.setup();
  analytics.trackEvent('Received Push Notification', {
    title,
    body,
    ...message.notification,
  });

  notifee.getBadgeCount().then((count) => {
    notifee.setBadgeCount(count + 1);
  });
});

notifee.getInitialNotification().then(({notification}) => {
  if (notification) {
    pushNotifHelper.setBadgeCount(0);

    let _notification = notification;

    if (notification.data.data !== undefined && typeof notification.data.data === 'string') {
      _notification = {
        ...notification,
        data: JSON.parse(notification.data.data),
      };
    }

    pushNotifHelper.updateRemoteNotifData(_notification);
  }
});

function HeadlessCheck({isHeadless}) {
  if (isHeadless) {
    return <Headless />;
  }

  return <Router />;
}

AppRegistry.registerComponent(appName, () => HeadlessCheck);

Any help and ideas would be appreciated.

@mikehardy
Copy link
Collaborator

Let's keep the discussion in one spot (I just reopened the original issue) but this is helpful information useful to reference from there thank you

resolving duplicate #266

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants