Android back button does not work

后端 未结 5 1141
星月不相逢
星月不相逢 2021-02-06 14:56

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         


        
5条回答
  •  难免孤独
    2021-02-06 15:44

    It is been handled here in the file Cocos2dxGLSurfaceView.java

    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:
    

提交回复
热议问题