문제

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!

도움이 되었습니까?

해결책

No i don't think so , when your application get killed because of lack of Memory your whole app process would be killed so in this situation onDestroy() may not be called and your app will back again on your launcher Activity unless you can save your application state on onPause() state before your app get killed.

다른 팁

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()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top