I have created an sample application for android and tested it in my htc android mobile. I want to know how to exit the application? can anyone give me sample code? thank you.
Asked
Active
Viewed 1.0k times
1
-
possible duplicate of [Quitting an application - is that frowned upon?](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon) – Konstantin Burov Apr 03 '11 at 11:00
4 Answers
0
You can exit your current activity by calling the finish()
method. If you also want to stop services you created you can call stopService(Intent i)
http://developer.android.com/reference/android/app/Activity.html#finish() http://developer.android.com/reference/android/content/ContextWrapper.html#stopService(android.content.Intent)

Mats Hofman
- 7,060
- 6
- 33
- 48
0
You can also override the finish() method and stop services, clean memoory...

Dayerman
- 3,973
- 6
- 38
- 54
-
`Activity` class has methods to override for handling lifecycle events. There's no guarantee that an overridden `finish()` will get called if the system decides it's time for your activity to close up shop. – Blrfl Apr 03 '11 at 12:09
-
-
That would be one way, but there's no guarantee `onDestroy()` will ever be called. See the `Activity` docs for an explanation. – Blrfl Apr 04 '11 at 00:28
-1
System.Exit(0);
//Use that to exit the entire application. not just an Activity

Ndupza
- 780
- 1
- 6
- 16