Android Activity onDestroy() is not always called and if called only part of the code is executed

Take a look at this: Activity OnDestroy never called? And this: http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29 Basically, there’s never a guarantee that onDestroy() will be called, and in some cases processes such as your app will be killed directly, bypassing the method call anyway.

Activity OnDestroy never called?

onDestroy() is called only when system is low on resources(memory, cpu time and so on) and makes a decision to kill your activity/application or when somebody calls finish() on your activity. So, to test your code() you can make a test button, that will call finish() on your activity. Read more here. Also, I believe … Read more

What is Activity.finish() method doing exactly?

When calling finish() on an activity, the method onDestroy() is executed. This method can do things like: Dismiss any dialogs the activity was managing. Close any cursors the activity was managing. Close any open search dialog Also, onDestroy() isn’t a destructor. It doesn’t actually destroy the object. It’s just a method that’s called based on … Read more

Android activity life cycle – what are all these methods for?

See it in Activity Lifecycle (at Android Developers). onCreate(): Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity’s previously frozen state, if there was one. Always … Read more

tech