Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top