Killing an Android App with the Home Key

对着背影说爱祢 提交于 2019-12-13 03:58:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!