1

I want to destroy whole application when am clicking exit button....

user1252191
  • 49
  • 1
  • 7

3 Answers3

0

There is no Exit button concept in Android. Simply call finish(); on your activities to destroy them.

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • This is not what the OP was asking, as this will not destroy a parent activity when called from a child. – Aleks G Apr 11 '12 at 07:43
  • Not quite. The concept is there: it means finish **all** activities of the application. I've seen quite a few apps that include *exit* function. Check Opera Mobile, for example. – Aleks G Apr 11 '12 at 07:45
  • that exit button is to kill any service in case they are running and/or to give user a feel that the app is closed (as in windows), otherwise it can always be resumed from Activity Stack. And if there was an exit concept by android, then they must have had provided something like *context.exit();* but unfortunately they dont – waqaslam Apr 11 '12 at 07:48
0

The most straight way is

finish();
System.exit(0);
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
0

try this code to close your application and all its activities

finish();
        Intent intent = new Intent(Intent.ACTION_MAIN); 
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        intent.addCategory(Intent.CATEGORY_HOME); 
        startActivity(intent);

Close application and launch home screen on Android

Community
  • 1
  • 1
vipin
  • 2,851
  • 4
  • 18
  • 32
  • its working but when i open application again it shows the previous activity how to exit... – user1252191 Apr 11 '12 at 11:36
  • check in your task manager that after exiting application is there alive or not ?? – vipin Apr 11 '12 at 11:41
  • okay i want to say when you call this segment all activities shoul get closed if they are not getting close there may be some problem but this way is very good to close application rather then system.exit(0); – vipin Apr 11 '12 at 12:55
  • if you have any problem let me know – vipin Apr 11 '12 at 12:56