-3

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.

Oguz Ozkeroglu
  • 2,960
  • 3
  • 35
  • 63
Jagan
  • 672
  • 1
  • 12
  • 37
  • 1
    check [this link](http://groups.google.com/group/android-developers/browse_thread/thread/4c1b8955ebfd5799) – Imran Rana May 30 '12 at 07:21
  • 1
    There 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 Answers4

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.

Community
  • 1
  • 1
COD3BOY
  • 11,724
  • 1
  • 36
  • 55
  • 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
  • @user179777 cheers ..happy coding :) also consider [Accepting answer](http://meta.stackexchange.com/q/5234/172471) if this solved your problem. :) – COD3BOY May 30 '12 at 08:41
  • 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
  • @user179777 what you want when you press back? – COD3BOY May 30 '12 at 10:18
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.

http://developer.android.com/reference/android/app/ActivityManager.html#killBackgroundProcesses%28java.lang.String%29

Mohammed Azharuddin Shaikh
  • 40,812
  • 14
  • 95
  • 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,357
  • 1
  • 19
  • 17