区分Android杀死应用程序和用户在最近的应用程序列表中将其刷掉 [英] Differentiate between Android killing the app and user swiping it off on the recent apps list

查看:508
本文介绍了区分Android杀死应用程序和用户在最近的应用程序列表中将其刷掉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个项目,在进行特定活动时,我们会显示本地粘性通知.当应用程序最小化时也应该是这种情况.我要做的是每当应用程序被杀死时删除本地通知(通过Android,由于内存不足,或者由用户,从最近的应用程序列表中滑动).

I am working on a project, where while being on a specific Activity we show a local sticky notification. That should also be the case when the app is minimized. What I have to accomplish is to remove the local notification whenever the app is killed (by Android, because of memory lack or by the user, with a swipe from the recent apps list).

通常,每当Android进行活动"以打开一些空间时,都会调用onDestroy.在其中一种情况下,这很好,但是从最近的应用程序列表中轻扫一个应用程序不会调用onDestroy,并且粘性通知会保留.

Usually onDestroy would be called whenever Android takes the Activity to open some space. That is fine in one of the cases, however swiping an app from the recent app lists doesn't call the onDestroy and the sticky notification stays.

我所做的是,我实现了一个空服务,当应用被杀死(刷卡和系统都被杀死)时,该服务将强制onDestroy以便删除通知.

What I did is, I implemented an empty Service which would force the onDestroy when the app is killed (both swipe and system kill) so I can get my notification removed.

但是,我想做的是区分刷卡和系统杀死.

However, what I would like to do is to differentiate between the swipes and system kill.

这有可能吗?

推荐答案

通常,如果Android由于在后台运行太长时间(或者因为它想要回收资源)而想要终止您的应用程序,则Android只会只需杀死托管您的应用程序的OS进程即可.它不会在任何活动"或服务"组件上调用finish()onDestroy().随着时间的推移,从最近的任务列表中滑动"的行为已更改,并且在不同的Android版本中有所不同.有人应该写一本书:-(

In general, if Android wants to kill your application because it has been in the background for too long (or because it wants to reclaim resources), Android will just simply kill the OS process hosting your app. It will not call finish() or onDestroy() on any Activity or Service components. The behaviour of "swipe from recent tasks list" has changed over time and is different in different Android versions. Someone should write a book about that :-(

这篇关于区分Android杀死应用程序和用户在最近的应用程序列表中将其刷掉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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