1

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.

David
  • 208,112
  • 36
  • 198
  • 279
user601367
  • 2,308
  • 12
  • 34
  • 44
  • 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 Answers4

1
public void onClick(View v) {
    finish();
}
bharath
  • 14,283
  • 16
  • 57
  • 95
Bikesh
  • 91
  • 4
  • 13
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
  • You mean to override onDestroy()? – Dayerman Apr 03 '11 at 19:01
  • 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