question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android: 'onNotification' not executing when app is closed and clicked to notification

See original GitHub issue

[android] Hello, when I put app in the background and I get push notification then onNotification is executed as I expect. But when I close app (using android back button) and I get push notification then onNotification is not executed.

I know onNotification is fired from Java in onNewIntent method. But I really need to pass some data from notification into JavaScript when application was closed before and I click on notification.

How to do it?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:39 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
didilcommented, Apr 25, 2017

shouldnt some of this be in the documentation ? it ended up working for me but its fairly non trivial to understand that you need a specific message format to get a notification displayed and clicked with the app closed to trigger onNotification

4reactions
frangeriscommented, Jul 20, 2016

Hey @kfiroo @amrdraz I’ve no idea why now is working 😐

This is what I did, I was using firebase endpoint (not working), then I changed to test using the code of @amrdraz (using GCM endpoint), start working, rollback and test again with firebase endpoint, works… 😕

Is possible that switching between endpoint could fix something behind scenes?

Another note is that data nested inside data is not required, the next request works on both (GCM, FCM):

curl -X POST -H "Authorization: key=<MY_KEY>" -H "Content-Type: application/json" -d '
{
  "data": {
      "title": "Hello there",
      "message": "some message text",
  },
  "to" : "<DEVICE_TOKEN>"
}' 'https://fcm.googleapis.com/fcm/send'

And from React native:

module.exports = React.createClass({
    componentWillMount() {
        PushNotification.configure({
            // popInitialNotification: true,
            onNotification: (notification) => {
                console.log(notification)
            }
        })
    }
})

Thank’s guys for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: 'onNotification' not executing when app is closed and ...
To show alert in android : in your android device -> settings -> App Notification -> select your app name and turn on...
Read more >
Start an Activity from a Notification - Android Developers
This is an activity that exists as a part of your app's normal UX flow. So when the user arrives in the activity...
Read more >
Handling Incoming Push Notifications in AWS Amplify - Medium
AWS Amplify provides two push notification configuration functions to configure how push ... This process does not open the closed app into your...
Read more >
Notifications Not Shown - Mobile Push
See Android Notification Categories for more details. 800. The app is currently In Focus. Keep the app running ...
Read more >
Push notification doesn't open specific screen when app is ...
SDK 41. Android / iOS expo-notifications I have a problem where I need to redirect user to specific post when he taps on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found