Android后退按钮不起作用 [英] Android back button does not work
问题描述
我正在使用cocos2dx制作一个小游戏,在我的游戏活动中,我提供了以下功能来处理后退按钮。
I am using cocos2dx to make a small game and in the activity of my game i give the following functions to handle back button.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return super.onKeyDown(keyCode, event);
}
@Override
public void onDestroy()
{
android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();
}
按下后退按钮我在logcat中收到以下警告
On pressing back button i get the following warning in my logcat
无法打开keycharmap文件
Can't open keycharmap file
加载keycharmap文件'/ system / usr / keychars时出错/qtouch-touchscreen.kcm.bin'。 hw.keyboards.65538.devname ='qtouch-touchscreen'
Error loading keycharmap file '/system/usr/keychars/qtouch-touchscreen.kcm.bin'. hw.keyboards.65538.devname='qtouch-touchscreen'
该调用未达到onKeyDown或onDestroy函数。
The call doesn't reach onKeyDown or onDestroy functions.
请告诉我为什么会出现此警告以及为什么我无法处理安卓后退按钮。
Please tell me why this warning is caused and why i cannot handle the android back button.
这些功能正常工作我的java android项目,但不在我的cocos2d-x项目中
The functions work fine on my java android project but not in my cocos2d-x project
推荐答案
此处已在文件 Cocos2dxGLSurfaceView.java
将其更改为以下,其中 myActivity
是cocos2dActicity
change it to below, where myActivity
is the cocos2dActicity
case KeyEvent.KEYCODE_BACK:
AlertDialog ad = new AlertDialog.Builder(myActivity)
.setTitle("EXIT?")
.setMessage("Do you really want to exit?")
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
((Cocos2dxActivity)myActivity).finish();
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).create();
ad.show();
return true;
case KeyEvent.KEYCODE_MENU:
这篇关于Android后退按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!