Activity.finish() x System.exit

Showing 1-6 of 6 messages
Activity.finish() x System.exit 1/21/10 12:46 PM

I've been using System.exit to quit the application. Is
Activity.finish a better approach? What would be the differences?



Re: Activity.finish() x System.exit Streets Of Boston 1/21/10 1:52 PM
System.exit() kills your entire process.
activity.finish() just hides, stops and destroys your activity. Your
process is still running.

You should not call System.exit(). It could mess up Android's handling
of the lifecycles of your activities and result in an awkward user-
experience (e.g. when killing the process, the previous activity from
which you laucnhed your activity may be gone as well. Android may try
to restart the process again and re-create that accidentally killed
parent-activity... but still).

Re: Activity.finish() x System.exit guich 1/21/10 5:24 PM
I just found a side-effect of using finish: my library is NOT
unloaded, and the application will not work if it is called again.


Re: [android-developers] Re: Activity.finish() x System.exit Dianne Hackborn 1/21/10 5:56 PM
You really should be able to just continue using the library.  It is not unloaded, so you don't need to reload it, and can use it again.

To be clear: using System.exit() is strongly recommended against, and can cause some poor interactions with the system.  Please don't design your app to need it.

You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Re: [android-developers] Re: Activity.finish() x System.exit andjarnic 1/21/10 10:43 PM
It's too bad the android team can't remove some methods like exit() to avoid these potential pitfalls that aren't documented very well (at least in most books). For guich, looks like you would need to implement some way of detecting that the library is already loaded, so as not to load it again.
Re: Activity.finish() x System.exit Albert 1/22/10 2:09 AM
What about this:
int pid = android.os.Process.myPid();

You exit the app asking android to kill your process. I think that
what is used in 3D games as most of them have and exit button, you
kill the process so that it wont drain battery and use memory.

Anyway if your app consist of only 1 activity you should call finish();