Home键监听器 [英] Home button listener

查看:131
本文介绍了Home键监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用setOnKeyListener我能够侦听除Home和End按键的所有物理按键,是否有可能赶上Home键的作用。

Using the setOnKeyListener I can able to listen for all physical buttons except Home and End button, is there any possibility to catch the action of Home button.

推荐答案

您不必赶Home键。如果用户preSS主页和其他一些活动涉及到前台,您的应用程序被切换到后台和的onPause()被称为在当前的活动。你可以覆盖该功能来清洁你需要搜索字符串或任何东西。

You do not need to catch Home button. If user press Home and some other Activity comes to foreground, your app goes to background and onPause() is called in your current Activity. You may override that function to clean search string or anything you need.

更新:

更干净的解决方案是在开始的重要活动时使用标志FLAG_ACTIVITY_NO_HISTORY。所以,当你的活动进入后台系统将正确地为你关闭它。

More clean solution is to use flag FLAG_ACTIVITY_NO_HISTORY when starting that critical activity. So, when your activity goes to background system will close it properly for you.

这篇关于Home键监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆