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?

1
  • 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. Commented Jun 29, 2014 at 10:20

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.