I want to exit the android application completely from any screen i also tried System.exit(0);
and finish();
but it only exit the current activity i want to exit completely. I used menu option for exit can any one help me in coding.
Asked
Active
Viewed 1,770 times
-3

Oguz Ozkeroglu
- 3,025
- 3
- 38
- 64

Jagan
- 692
- 1
- 12
- 38
-
1check [this link](http://groups.google.com/group/android-developers/browse_thread/thread/4c1b8955ebfd5799) – Imran Rana May 30 '12 at 07:21
-
1There are many similar questions like [here](http://stackoverflow.com/questions/2042222/close-application), [here](http://stackoverflow.com/questions/2092951/how-to-close-android-application) and [here](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238) also – Imran Rana May 30 '12 at 07:36
4 Answers
2
Press the home button! you're done!
You need not really think about exiting the application(assuming you're asking for a exit button). This is not how Android apps usually work.
Please read upon this link for more information : When to Include an Exit Button in Android Apps (Hint: Never)
and this question also might be helpful.
-
when i used home button the activity and services run in bg when i click the app again it comes to a same activity i want to restart the app when i exit and come back – Jagan May 30 '12 at 07:30
-
1@user179777 if you want to go that way, use `android:noHistory="true"` in the manifest for all your activities :) and `finish()` your current activity ..youre done! :) – COD3BOY May 30 '12 at 07:35
-
and also i want the back button in android to be work if i put this the back button will be working ? – Jagan May 30 '12 at 08:16
-
@user179777 umm I dont get you completeley.the back key will work fine and if want to do something when user presses the back key, you should be overriding `onBackPressed ()` method .. – COD3BOY May 30 '12 at 08:27
-
i try the android:noHistory="true" is working fine but i can't used he back button in android the project exit when i click the back button any solution – Jagan May 30 '12 at 09:57
-
1
used this in your coding in your program
android.os.Process.killProcess(android.os.Process.myPid());
this will kill your process
0
ActivityManager.killBackgroundProcesses(PackageName) will be helpful.

Mohammed Azharuddin Shaikh
- 41,633
- 14
- 96
- 115
-1
When you start an activity, use startActivityForResult().
Intent intent = new Intent(MainActivity.this, NewActivity.class);
startActivityForResult(intent, ActivitiesRequests.REQUEST_FROM_NEW_ACTIVITY);
Then, if an activity wants to signal its caller to exit as well, it can use a result code: setResult(RESULT_CANCELED);. It is then caught in the MainActivity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode)
{
case ActivitiesRequests.REQUEST_FROM_NEW_ACTIVITY:
if (resultCode == RESULT_CANCELED)
finish();
break;
}
super.onActivityResult(requestCode, resultCode, data);
}

Steelight
- 3,347
- 1
- 20
- 17