Tal Kanel Tal Kanel - 11 months ago 71
Android Question

what exactly Activity.finish() method is doing?

I'm developing android applications for a while, and followed a lot of posts about activity life cycle, and application's life cycle.

I know

method calls somewhere in the way to
, and also removing the activity from stack, and I guess it somehow points to operating system and garbage collector that he can "do his trick" and free the memory when it find it a good time doing so....

I came to this post -
Quitting an application - is that frowned upon? and read Mark Murphy's answer.

It made me a bit confused about what exactly the
method actually does.

Is there a chance I'll call
won't be called?


When calling finish() on an activity, the method onDestroy() is executed this method can do things like:

  1. Dismiss any dialogs the activity was managing.
  2. Close any cursors the activity was managing.
  3. 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