Normally while calling finish(), we are expected to call onPause(), onStop() and onDestroy(). Most of the times it is working fine. But sometimes finish() only calls onPause() i.e. onStop() and onDestroy() are not calling sometimes. Why it is like so? What happens finish() for not calling onStop() and onDestroy(). I have put log in finish() method Activity.java. But in working and non working conditions logs are same. Please help.
-
finish() does not call onDestroy() – No_Rulz Jan 08 '14 at 04:38
2 Answers
According to developer docs, onStop()
and onDestroy()
are Killable:
Note the "Killable" column in the above table -- for those methods that are marked as being killable, after that method returns the process hosting the activity may killed by the system at any time without another line of its code being executed. Because of this, you should use the onPause() method to write any persistent data (such as user edits) to storage.
So onStop()
and onDestroy()
may or maynot be called, it depends on how system handle it.

- 825
- 6
- 16
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 a certain state. So your instance is still alive and very well* after the superclass's onDestroy() runs and returns.Android keeps processes around in case the user wants to restart the app, this makes the startup phase faster. The process will not be doing anything and if memory needs to be reclaimed, the process will be killed
finish() Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().