How know when android app was force killed

921 Views Asked by At

As the title suggests I would like to know when an android app was force killed by the operating system.
I need that for custom logs purpose and to try to find a bug in my app.
My app is wake upped with a notification from FCM service, but sometimes seems that notification is not received from the phone and so I cannot wake the app.

Any suggestions for this issue?
Thank you very much to all

2

There are 2 best solutions below

0
AudioBubble On
7
Shlomi Katriel On

Android does not officially expose such API. As mentioned in the referenced answer in the comments, the app process is being killed without leaving any trace.

However, you can persist some sort of a keep-alive watermark. Immediately after your app is created, update the watermark every X minutes/seconds (don’t use work manager periodic work since it wakes up the app, which beat the purpose).

Once your app is revived after being force-stopped, you can check when you app was alive and determine if it was killed.

The more frequently you update the watermark, the more accurate this workaround will be