简体   繁体   English

如何检测我的应用何时通过滑动终止?

[英]How to detect when my app is terminated with a swipe?

I have an Android existential question: 我有一个Android存在的问题:

Does an App's onDestroy() get called when I kill it by swiping it out of the task manager? 通过将其从任务管理器中刷出杀死应用程序的onDestroy()是否会被调用?

If not... how can I detect a "killing" swiping event on the app, and do some final stuff beore it dies? 如果不是,我该如何在应用程序上检测到“杀人”刷卡事件,并且死了一些最后的东西呢?

onDestroy() onDestroy()

Perform any final cleanup before an 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. 发生这种情况的原因可能是活动即将结束(有人在其上执行finish(),或者是因为系统暂时销毁了此活动实例以节省空间。

Note: do not count on this method being called as a place for saving data! 注意:不要指望此方法被称为保存数据的地方!

There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away. 在某些情况下,系统会简单地终止活动的托管过程,而无需在其中调用此方法(或任何其他方法),因此不应将其用于处理在过程消失后仍然存在的事情。

Instead, rely on onPause() and onStop() to do any final work before your app goes out of view. 而是依靠onPause()onStop()完成应用程序的所有最终工作。

Is your main concern the "swiping" event or just saving data? 您主要关注的是“刷卡”事件还是仅保存数据? :) :)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM