0

I'm currently getting into android development. I try to let the user end the application by a menu button. This is my attempt:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_exit) {
        android.os.Process.killProcess(android.os.Process.myPid());
        super.onDestroy();
    }

    return super.onOptionsItemSelected(item);
}

The application window closes, but when I switch to the "open applications window" it is still there. How can I end/kill/close/shutdown my application completely?

namespace
  • 404
  • 3
  • 6
  • 18
  • 2
    Using `finish()` instead of `super.onDestroy()` ends your activity. The window you call `open applications` is the `recents` window: the last used applications that may or may not be running. – nhaarman Jun 29 '14 at 10:20

1 Answers1

1

You should think about closing your app twice, since it is not the way Android apps usually work. Instead of this you should use the code as follow:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_exit) {
        finish()
    }

    return super.onOptionsItemSelected(item);
}

If you really want to exit your application manually, please check out the accepted answer from the following post: How to close Android application?

Community
  • 1
  • 1
Robin
  • 709
  • 2
  • 8
  • 20