Home键点击事件处理的android [英] Home button click event handling android

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

问题描述

我想叫某些功能显示在homebuttonclick事件pressing通知。

I wanted to call certain function for showing notifications on pressing of homebuttonclick event.

我refered 的博客。

I refered this blog.

写code为:

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event){
        if(keyCode == KeyEvent.KEYCODE_HOME){
            APP_STATUS="SLEEP";

          LocalToNotification();

        }
        return true;
    }   

但不幸的是它不工作。

But unfortunatly it was not working.

我通过调试器进行测试,但观察到调试器也没有正在添加这条线code在pressing HOME键。

I tested through debugger, but observed that debugger is also not comming on this line of code upon pressing home button.

什么是错在上述code?

What is wrong in above code?

请帮我。

推荐答案

在较旧的Andr​​oid版本,这是工作。但是Android改变了这一点,因为他们说:主页按钮应留在家按钮,他们不希望任何人覆盖主页按钮。因为这个原因,你的code不工作了。

On older Android version this is working. But Android changed this, because they say "Home Button should stay Home Button" and they don't want that anybody override the Home Button. And because of this reason your code is not working anymore.

如果你想要做的事情时,home键是pressed,然后为此在的onPause方法。

If you want to do something when the home button is pressed, then do this in the onPause method.

这篇关于Home键点击事件处理的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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