react-native-fcm: Android: run code when app is killed
I’m trying to run some code when I receive a notification with my app killed. I haven’t got any success on my Android app (I’m not targeting IOS yet).
I’ve setup a fetch call to a log server directly on my index.android.js file, just to log if the app is being launched. I’ve also puts logs on FCM.getInitialNotification promise and FCMEvent.Notification event. Neither of these logs get called when I send notifications with the app closed (I close it by swiping it away from “Recent Screens”).
To send the notifications, I’m using fcm-node package, with the following configuration:
const message = {
to: registrationToken,
data: {
my_data: "test",
},
};
Sending push notifications with the property notification (and its title and body) set will show in the device, with the app in background or killed.
The package versions I’m using are listed below.
{
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-fcm": "^7.0.0",
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 33 (9 by maintainers)
@JulioC released in v7.5.0. Now android can trigger JS code when app is killed. Haven’t find iOS implementation. Let me know if it exists You can close the issue if it works for you.
@JulioC great finding. I will see if I can do similar things. But still it may be only available for android
@evollu when using the library, any notification received when the app is on background (in android), a new instance of javascript app is created and the same code you use for the UI is executed, but nothing is shown.
I don’t know about the details, but I believe these lines are the one responsible for executing the javascript code. They use ReactInstanceManager.createReactContextInBackground
I’ve just hit this exact problem. I can see the
Remote message receivedlog fromMessagingService.javawhich shows the notification has hit the device, but then nothing more happens.I’m presuming this library is supposed to handle receiving notifications when the app is closed? If so, how has this ever worked? It seems like a fairly fundamental issue…
just a quick update - upgraded to 7.5.1 and it worked like a charm! thanks again 😃
@zkrige thanks for your update. I haven’t tested that scenario. Good to know that it works
Facing the same issue here - notifications work fine when app is in foreground or background. But not able to get it working when app is killed (swipe away from “recent apps” screen)
Still no update on this? This is an important use case for background data messages