主要code_home不会被调用ANDROIDcode_home、ANDROID

由网友(??請勿、模仿)分享简介:嘿,我有一个code,它是这样的:Hey I have a code that looks like this:public boolean onKeyDown(int keyCode, KeyEvent event) {if (event.getAction() == KeyEvent.ACTION_DOWN)...

嘿,我有一个code,它是这样的:

Hey I have a code that looks like this:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_HOME:
            System.out.println("sdfadsfadsf");
            finish();
            return true; }
  } return super.onKeyDown(keyCode, event);}

我的问题是,是,无论是应用程序,也没有终止中的println被执行。谁能告诉我什么,我这里做错了什么?该应用程序应该关闭,当用户presses home键。我这样做是因为性能问题我的用户体验,当他们打开其他应用程序。我可以使应用程序更高性能,高效率,但在这种类型的应用程序,实在没有必要保持运行。

My problem is, that neither the app terminates nor the println gets executed. Can someone tell me what I do wrong in here? The app should get closed, when a user presses the home key. I do this because of performance issues my users experience when they open up other apps. I could just make the app more performance-efficient but in this type of app, there is really no need to keep it running.

推荐答案

在设计上的Home键不能被截取,从而键code_HOME 将不再发送任何回调。您只可以推断在Home键是pressed。

By design the Home key cannot be intercepted, thus KEYCODE_HOME will not be sent in any callback. You can only infer when Home key is pressed.

阅读全文

相关推荐

最新文章