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: run code when app is killed

See original GitHub issue

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",
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:33 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
evollucommented, Jul 31, 2017

@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.

4reactions
evollucommented, Jul 31, 2017

@JulioC great finding. I will see if I can do similar things. But still it may be only available for android

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to execute code before Android app is killed
You should be able to do this with a Service. Start a service when your app was started. Override the onTaskRemoved method
Read more >
Foreground service killed when receiving broadcast after ...
It seems the bug is in the broadcast code. If not for that, the service will not be killed. Swiping calls am.removeTask on...
Read more >
Service | Android Developers
Note that services, like other application objects, run in the main thread ... be a foreground process to ensure this code can execute...
Read more >
What function is run when app is killed from the "app manager ...
First, everything works well in the editor. My problem is on Android : When the application is launched, i clicked on the Home...
Read more >
Run a code to work even if app is killed in android - MSDN
You need Foreground Sevice , add your logic into custom service , it is still alive even if your app is closed. Refer...
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