简体   繁体   中英

onDestroy being called

I can't figure out the onDestroy() behaviour. My question is: Is there any chance that an activity will be killed without calling it's onDestroy() while not killing the hole app? I mean, Could it be that I'll get back to my app (to an activity other then the activity that the launcher calls) and be in a situation where one activity was killed without calling it's onDestroy()?

I have a need to know that if I get back from the background to an activity that there is no way some of my activities where killed without it's onDestroy.

Thanks!

不,我不这么认为,当您的应用程序由于缺少内存而被杀死时,整个应用程序进程将被杀死,因此在这种情况下,可能无法调用onDestroy(),并且您的应用程序将再次返回到启动器活动中,除非您可以保存在您的应用被杀死之前,您在onPause()状态上的应用状态。

yes, Android will kill a least frequently used activity if there is not enough memory is available for the newly started app. Also the back button triggers the onDestroy(). A best bet is to save your app state. Here is an example to a similar question how to save and restore your current instance.

As stated in the API documentation Activity#onDestroy():

Note: do not count on this method being called as a place for saving data!

http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29

And don't forget to call super.onDestroy()

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