android – 'RNFirebaseBackgroundMessage' Event not triggered while receiving data notification in React Native Application-ThrowExceptions

Exception or error:

I am using react-native-firebase@5.2.3. I had created a headless task to receive the data notification, and my server is sending me a data notification but it is not reflecting in my application although i had created the event for this.
It is working finely in android < v7. But not working in android version > v7.

I’m not getting anything in console, while server has sent me the data-only notification. Once this callback on headless task execute i will code here to show notification but there is no event triggering.

Environment :

    OS: Ubuntu
        "react": "16.6.3",
        "react-native": "^0.58.6",
        "react-native-firebase": "^5.2.3",

My code is given below.

import {AppRegistry} from 'react-native';
import 'babel-polyfill';
import App from './App';
import {name as appName} from './app.json';
console.disableYellowBox = true;

const bgMessaging = async(messages) => {
    console.log("BgMessaging",messages);
    return Promise.resolve();
};

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging);
AppRegistry.registerComponent(appName, () => App);
How to solve:

I got the solution.
When your application is set to use battery in optimised way, then it does not allow to execute the headless task, So, simply i had changed my app’s battery setting to normal mode and it started working finely.
My android device was set to use all application in battery optimisation. That’s why i had faced this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *