主要code_home不会被调用ANDROID [英] Keycode_home doesn't get called ANDROID
问题描述
嘿,我有一个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.
这篇关于主要code_home不会被调用ANDROID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!