[英]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.