有什么办法退出应用程序时,home键是pressed在Android?有什么办法、应用程序、home、pressed

2023-09-06 19:36:28 作者:油﹌漆店里の老情亼

我要杀死应用程序时,用户presses home键。有没有办法做到这一点在Android?

I want to kill the app when user presses the home button. Is there any way to do this on Android?

推荐答案

我实现通过重写类似 Activity.onUserLeaveHint()。此方法被调用一次,home键是pressed但我觉得在那里有一些注意事项我不记得现在。即它得到了号召情况下,我不希望我的应用程序完成,并不得不把标志prevent不必要的退出。

I implemented something similar by overriding Activity.onUserLeaveHint(). This method gets called once home key is pressed but I think there where some caveats I can't remember right now. Namely it got called on situations I didn't want my application to finish and had to put flags to prevent unwanted exits.