Can't exit an Android application
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.getIte开发者_StackOverflow社区mId()) {
case EXIT:
try {
this.finish();
} catch(Exception e) {
}
break;
}
return false;
}
The answer is that you shouldn't exit your Android application.
Have a look at this excellent answer for more information.
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.
//Put this in to exit an application. Not a window
System.Exit(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.
精彩评论