简体   繁体   English

用户从android中的后台删除应用程序时如何检测事件?

[英]How to detect event when user removes app from background in android?

I need to reset notification when user removes my app from background.So I need to have an event of remove app from background. 当用户从后台删除我的应用时,我需要重置通知。因此,我需要发生一个从后台删除应用的事件。

Please help me out. 请帮帮我。 Suggestion appreciated. 建议表示赞赏。 Thanks. 谢谢。 Kind Regards. 亲切的问候。

Official android documentation 官方android文档

Activity.onDestroy()

The final call you receive before your activity is destroyed. 活动销毁之前收到的最后一个电话。 This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method. 这可能是由于活动即将完成(有人在其上称为finish()),或者因为系统正在临时销毁该活动实例以节省空间。您可以使用isFinishing()方法区分这两种情况。

http://developer.android.com/reference/android/app/Activity.html#onDestroy() http://developer.android.com/reference/android/app/Activity.html#onDestroy()

  Whenever an app is removed from background it's processID is changed. 

Simply compare those pid(Process ID). 只需比较那些pid(进程ID)。

    int oldProcessID = SettingsSharePref.readProcessID();
    int newProcessID = android.os.Process.myPid();//getProcessID(mContext);/

    if( oldProcessID != newProcessID ){
        //if it killed or started as a new process...
        SettingsSharePref.saveProcessID(newProcessID);
    }

In the life cycle of android . 在android的生命周期中。 you can find onDestroy() method, with the help of this you can have a broadcast receiver or service based on your requirement. 您可以找到onDestroy()方法,借助此方法,您可以根据需要获得广播接收器或服务。 Hope you got a solution 希望你有一个解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测来自后台服务或其他应用的Android应用启动 - How to detect launch of an app in Android from a background service or another app 检测用户何时将应用置于后台 - Detect when user put the app in background 如何检测特定的 Android 应用程序何时进入后台? - How to detect when a specific Android app goes to the background? 如何检测Android应用程序何时进入后台并返回前台 - How to detect when an Android app goes to the background and come back to the foreground 如何检测 android 应用程序何时在后台和前台处理一些代码 - how to detect when android app in background and foreground to handle some code Android:当用户从最近的任务列表中删除应用程序时,停止工作小工具 - Android : Stopping works Widget when user removes app from recent tasks list 检测 Android 应用何时进入后台 - Detect when Android app is going to background Android-如何检测用户何时单击最新应用? - Android - How to detect when user click recent app? 如何检测用户何时启动另一个应用程序? (Android) - How to detect when the user launches another app? (Android) 即使我的应用程序在 android 的后台,如何接收广播事件 - How to receive broadcast event even when my App is in background in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM