如何捕获按下主页按钮?
在我的应用程序中,如果用户单击主页按钮但也想维护活动堆栈,我想打开登录屏幕。
有什么办法可以做到这一点吗?
In my application, I would like to open login screen if user click home button but also want to maintain activity stack.
Is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有直接的方法可以做到同样的事情。就像您无法获取 HOME 键的 KeyDown 事件一样。但我们可以通过以下代码捕获 HOME 键并保持在同一屏幕中
There is no direct way to do the same. like you can not get the KeyDown event for the HOME key. but we can get the HOME key captured and stay in the same screen by following code
实际上你应该覆盖主页按钮:
Actually you should override to home button:
出于安全原因,您绝对无法捕获主页按钮单击事件。
但是,您可以通过重写方法
onNewIntent()
来执行一些操作,以及按 Home 按钮执行的操作。You cannot capture Home button click event definitely for security reasons.
However, you can do something along with actions taken by pressing Home button by overriding method
onNewIntent()
.