简体   繁体   中英

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

I have an Android existential question:

Does an App's onDestroy() get called when I kill it by swiping it out of the task manager?

If not... how can I detect a "killing" swiping event on the app, and do some final stuff beore it dies?

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.

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.

Is your main concern the "swiping" event or just saving data? :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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