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.

onNotification is not Called android When App is killed #1034

See original GitHub issue

Hi,

I have setup for the Local and remote notification in the App.js file, it’s working fine in the iOS device also working fine android when App is not killed the onNotification is called.

But when App is killed in android at that time there is not called onNotification.

App.js

PushNotification.configure({
    // (optional) Called when Token is generated (iOS and Android)
    // smallIcon: "ic_notification",
    onRegister: function (token) {
      console.log('TOKEN:', token.token);
      setStoredData('deviceToken', token.token)
    },
    // (required) Called when a remote or local notification is opened or received
    onNotification: function (notification) {

      console.log('** NOTIFICATION: **', notification);

      if (Platform.OS === 'ios') {
        if (notification.alert.length !== 0) {
          handleNotification(notification)
          notification.finish(PushNotificationIOS.FetchResult.NoData);
        }
      } else {
        handleNotification(notification)
      }
    },
    senderID: "74898989898”,
    permissions: {
      alert: true,
      badge: true,
      sound: true
    },
    popInitialNotification: true,
    requestPermissions: true,
  });

And in the Home.js Called for notification.

PushNotification.localNotification({
      /* Android Only Properties */
      id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
      ticker: "My Notification Ticker", // (optional)
      autoCancel: true, // (optional) default: true
      largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
      smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
      bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
      subText: "This is a subText", // (optional) default: none
      color: "black", // (optional) default: system default
      vibrate: true, // (optional) default: true
      vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
      tag: 'some_tag', // (optional) add tag to message
      group: "group", // (optional) add group to message
      ongoing: false, // (optional) set whether this is an "ongoing" notification

      /* iOS and Android properties */
      title: "My Notification Title", // (optional)
      message: "My Notification Message", // (required)
      playSound: false, // (optional) default: true
      soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
      number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
      repeatType: 'day', // (Android only) Repeating interval. Could be one of `week`, `day`, `hour`, `minute, `time`. If specified as time, it should be accompanied by one more parameter 'repeatTime` which should the number of milliseconds between each interval
      actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
    });

I Added local notification in Home.js so that is not called.

Can you please help me

Thanks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

2reactions
MahbbRahcommented, Apr 29, 2019

@claudiumatei I face with a problem. When app is in foreground, it shows notification. When app is in background, no notification display. If I open app again, the notification show. Do you face with this issue ?

Yes, Frustrating thing. no workaround here 😦 no one say’s about this.

1reaction
1fabiopereiracommented, Jan 15, 2020

After many hours trying to fix this problem I think that I found the problem, When I change the build mode, from development to production the onMessage method works for all scenario (killed app, background and foreground) and both platforms.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onNotification() is not fired when app is killed - Stack Overflow
I am not positive but when I remember correctly killing (alias force closing) an app disables the onNotification functionality in Android ...
Read more >
Handle remote notifications when app is killed
When the app is killed, DidReceiveRemoteNotification() is not called, so we can not process the notification. However, the notification will be shown as...
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 >
NotificationListenerService - Android Developers
Notification was canceled by the owning user context being stopped. ... but had been killed before calling stopSelf(int) for that Intent.
Read more >
Tapping on the notification does not launch the App if the App ...
Not the answer you're looking for? Browse other questions tagged. android · notification · mobilepush-android · push-notification. or ask your ...
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