如何在Android 8.0 Oreo API 26及更高版本上检测到应用终止 [英] How can I detect app kill on Android 8.0 Oreo API 26 and after

查看:90
本文介绍了如何在Android 8.0 Oreo API 26及更高版本上检测到应用终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测应用程序进程是否终止,才能在服务器端运行一些清理任务.

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

在常见问题上提到的解决方案不再适用于Android 8或更高版本.是否可以检测Android 8或更高版本上的应用程序终止?

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?

Android 8之前的解决方案:

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?

推荐答案

您可以使用链接的相同解决方案,但是从Oreo开始,SERVICE应该以FOREGROUND_SERVICE的形式启动,否则它将在系统中停留5秒. 因此,您可以重复使用90%的先前代码,但是您需要根据新的Oreo要求进行更改.

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.

但是,如果通过选择终止"按钮从"Android设置->应用程序"页面中杀死该应用程序,即使所有后台服务也同时被杀死,因此,如果发生这种情况,这些方法将不再起作用.

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.

这篇关于如何在Android 8.0 Oreo API 26及更高版本上检测到应用终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆