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.

AppState changes to active when app receives notification in killed state

See original GitHub issue

I am able to receive notification in all 3 states (killed/foreground/background).

The data gets printed in console when the notification arrives, however I was not receiving any data from the notification when clicked on it from the notification tray.

  1. When I just send data, I can see the data getting printed in console the moment I send the notification but no icon in the notification array,
const payload = {
  data: {
    title: 'Hi',
    body: 'body',
    message: 'Message',
  }
}
  1. When I just send data with notification, I can see icon in the notification array, but when I click on it, there is no data passed to the application in background and killed state
const payload = {
  data: {
    title: 'Hi',
    body: 'body',
    message: 'Message',
  },
  notification: {
    title: 'Hi',
    body: 'body',
    message: 'Message',
  }
}
  1. Updated: When I just send data with custom_notification, I can see icon in the notification array with data getting printed in the console as soon as the notification arrives in the notification tray, but when I click on it, there is no data passed to the application in background and killed state.
const payload = {
  data: {
    custom_notification: {
      title: 'Hi',
      body: 'body',
      message: 'Message',
    }
  },
}

So, finally I decided to save data in asyncStorage whenever I receive the notification and if the user clicks on it I retrieve the notification data from storage. For this I heavily rely on appState.

The main problem here is that, when app is in killed state, I manage to store the data, but my function is unable to run as the AppState gets set as active when the notification arrives in killed state. Now when I click on the notification the AppState still remains active and my handler does not run at all.

RN: 0.45.1, FCM: 13.3.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
sahil290791commented, May 30, 2018

@balapkm you need to store the notification payload when it arrives in sleep/killed state using AsyncStorage and then when the user actually clicks on it, read it from AsyncStorage.

If you add a listener for killed state you will notice that the app receives the payload in killed state but when the user clicks on the notification the payload gets lost.

1reaction
evollucommented, Jun 13, 2018

@sahil290791 perhaps I should merge sdk-26 into main as it is getting stable

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get the dead or killed Appstate for an Android app ...
The AppState only gives the active, inactive & background stages of an the app. How can I get the can the killed or...
Read more >
Activity state changes - Android Developers
Activity state changes · Activity or dialog appears in foreground · User presses or gestures Back · System kills app process.
Read more >
How to Implement Push Notifications [Real Case] - Freshcode
This research explored a number of native code solutions within iOS development to handle push messages in the killed app state clearly. Notifications...
Read more >
Determine if the App is terminated by the User or by iOS
How can I identify if an iOS app has been terminated by the User or by iOS? ... tho, what your app can...
Read more >
The execution states of an iOS application | by Chinthaka Perera
At the Inactive app state the application isn't receiving any events (The UI also not accessible at this state. So, the UI events...
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