How can I detect app kill on Android 8.0 Oreo API 26 and after

大憨熊 提交于 2020-05-28 04:09:20

问题


I need to detect application process kill to run some clean up tasks on server side.

The solutions which is mentioned on popular questions are no longer works on Android 8 or later. Is there a way to detect application kill on Android 8 or later?

Pre-Android 8 solutions:

  • How to know when my app has been killed?
  • How to handle code when app is killed by swiping in android?

回答1:


You could use same solutions you linked, but starting from Oreo a SERVICE should be started as FOREGROUND_SERVICE or it will be killed withing 5 seconds from the System. So you can reuse 90% of previous code but you need to do changes according to new Oreo requirements.

However if the App is killed from "Android Settings --> Apps" page by selecting the "Terminate" button, even all Background Services are killed in the same time, so if this case occurs those methods will not work anymore.



来源:https://stackoverflow.com/questions/54017641/how-can-i-detect-app-kill-on-android-8-0-oreo-api-26-and-after

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!