Brett Brett - 1 year ago 121
Android Question

how to close android app completely

I created an android application with a logout option in

. The Logout works perfectly but when I press the back button again it takes me to the previous activity, and when it gets a null value it redirects to login screen. Now my login screen appears again and again. I want to close the app completely when I press the back button but don't know how.

Here is my code to handle the back button press in the login screen:

public void onBackPressed() {
new AlertDialog.Builder(this)
.setMessage("Are you sure you want to exit?")
.setNegativeButton(, null)
.setPositiveButton(android.R.string.yes, new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {

please help guyss..

Answer Source

To Quit Application on Button click use this code :

Intent intent = new Intent(Intent.ACTION_MAIN);

Try it..

To kill the complete app and remove it from Runningapp list kill the app through its pid(its nasty)... use this lines before above code.

int pid = android.os.Process.myPid();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download