问题
I have an android app, and when the Home key is pressed I want it to terminate. Period. I dont want it hanging around running in the background. I just want it terminated. What's the best or prferred method to do this?
回答1:
No you don't.
Trying to "kill" your app is an Android antipattern.
Trying to catch the home key is also an Android antipattern.
There is a vast amount of material substantiating these points. If you think you do want your application killed, you're just plain wrong.
回答2:
You can use finish();
to terminate an activity.
来源:https://stackoverflow.com/questions/10963715/killing-an-android-app-with-the-home-key