1

When I exit my android application it resumes to the previous screen. How can I exit the Android application properly?

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()) {
         case EXIT:
             try {
                 this.finish();
             } catch(Exception e) {
             }
             break;
      }
      return false;
 }
David Webb
  • 190,537
  • 57
  • 313
  • 299
saravanan
  • 21
  • 1
  • 5

4 Answers4

5

The answer is that you shouldn't exit your Android application.

Have a look at this excellent answer for more information.

Community
  • 1
  • 1
David Webb
  • 190,537
  • 57
  • 313
  • 299
1
 this.finish();

will only finishes your current activity , that's the reason your resuming to previous screen.

In android you can't kill the application.

Still you want to kill your application , then kill your process ID.

brig
  • 3,721
  • 12
  • 43
  • 61
0
//Put this in to exit an application. Not a window
System.Exit(0);
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Ndupza
  • 780
  • 1
  • 6
  • 16
0

If I don't exit my Android app such as myTuner, the radio station keeps playing...stopping it from playing is kind of ridiculous when exiting to give back the phone its memory makes every bit more sense. Whoever thought of allowing Android apps to just accumulate un-exited and slow down your phone made a huge mistake in my opinion.

It's how people want to user their phone that matters more than how someone else thinks they have to use it. I prefer freedom of choice for something that makes more sense. Make apps you can exit out of like other OSes allow for.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '22 at 13:16