[] setBackgroundMessageHandler does not get called for sometime after Killing the app

Author: rawatmanojCreated Aug 14, 2025Updated Jan 29, 2026
Labelstype: bugplatform: androidplugin: messagingWorkflow: Needs Reviewresolution: solution-provided

Issue

setBackgroundMessageHandler is not getting called for sometime after I kill the app background in Android. After some time I get the notification and further notifications are coming fine. But if I kill the app again it will take time again to get notification.

javascript
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';

messaging().setBackgroundMessageHandler(async remoteMessage => {
  console.log('Message handled in the background!', remoteMessage);
  // handleBackgroundNotifcation(remoteMessage);
  pushLocalNotification(remoteMessage);
});

if (__DEV__) {
  require('./ReactotronConfig');
}
AppRegistry.registerComponent(appName, () => App);

Project Files

Javascript

Click To Expand

package.json:

json
    "@react-native-firebase/analytics": "^21.10.1",
    "@react-native-firebase/app": "^21.10.1",
    "@react-native-firebase/app-check": "^21.10.1",
    "@react-native-firebase/crashlytics": "^21.10.1",
    "@react-native-firebase/dynamic-links": "^21.10.1",
    "@react-native-firebase/messaging": "^21.10.1",
    "@react-native-firebase/perf": "^21.10.1",
    "@react-native-firebase/remote-config": "^21.10.1",

firebase.json for react-native-firebase v6:

json
# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
ruby
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end



target 'MashreqMobileApp' do
  use_expo_modules!

  if ENV['EXPO_USE_COMMUNITY_AUTOLINKING'] == '1'
    config_command = ['node', '-e', "process.argv=['', '', 'config'];require('@react-native-community/cli').run()"];
  else
    config_command = [
      'node',
      '--no-warnings',
      '--eval',
      'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
      'react-native-config',
      '--json',
      '--platform',
      'ios'
    ]
  end

  # Read APP_ID from ../.app.build
  def read_app_id
    env_file = File.expand_path('../.app.build', __dir__)
    if File.exist?(env_file)
      File.foreach(env_file) do |line|
        if line =~ /^APP_ID=(.*)/
          return $1.strip
        end
      end
    end
    nil
  end

  config = use_native_modules!(config_command)

  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  pod 'FirebaseCoreExtension', :modular_headers => true
  pod 'FirebaseCrashlytics', :modular_headers => true
  pod 'FirebaseInstallations', :modular_headers => true
  pod 'GoogleDataTransport', :modular_headers => true
  pod 'nanopb', :modular_headers => true
  pod 'Firebase/Crashlytics'
  pod 'react-native-google-maps', :path => '../node_modules/react-native-maps'
  pod 'FirebaseRemoteConfig', :modular_headers => true
  pod 'FirebaseABTesting', :modular_headers => true
  pod 'RNSecureStorage', :path => '../node_modules/rn-secure-storage/ios' # After the upgrade to RN 0.76 this is required to link the library correctly
  pod 'TrustKit', :modular_headers => true

  app_id = read_app_id
  if app_id.nil? || app_id.empty? || app_id == 'MASHREQ_PAK'
    pod 'mashreq-rn-covalent', :path => '../node_modules/@mashreq/mashreq-rn-covalent'
  end

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => true,
    :fabric_enabled => false,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      :ccache_enabled => ENV['TF_BUILD'] == 'True'
    )
    installer.pods_project.targets.each do |t|
      if t.name.start_with?("AEP")
        t.build_configurations.each do |bc|
            bc.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -no-verify-emitted-module-interface'
        end
      end
    end

    # TODO: Ask KYC team to remove bitcode from the EFR lib and remove the step below
    bitcode_strip_path = `xcrun --find bitcode_strip`.chop!

    def strip_bitcode_from_framework(bitcode_strip_path, framework_relative_path)
      framework_path = File.join(Dir.pwd, framework_relative_path)
      command = "#{bitcode_strip_path} #{framework_path} -r -o #{framework_path}"
      puts "Stripping bitcode: #{command}"
      system(command)
    end

    framework_paths = [
      "../node_modules/@mashreq/mashreq-rn-efr/ios/EFRSDK.xcframework/ios-arm64/EFRSDK.framework/EFRSDK",
    ]

    framework_paths.each do |framework_relative_path|
      strip_bitcode_from_framework(bitcode_strip_path, framework_relative_path)
    end
    # END OF TODO: Ask KYC and NEO EGY Onboarding teams to remove bitcode from the libs they are using and remove the step above

  end
end

target 'PushTemplateExtension' do
  pod 'AEPNotificationContent'
end

AppDelegate.m:

objc
// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

groovy
// N/A

android/app/build.gradle:

groovy
// N/A

android/settings.gradle:

groovy
// N/A

MainApplication.java:

java
// N/A

AndroidManifest.xml:

xml
<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • 21.10.1
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y & 5.0.4


Source: invertase/react-native-firebase