Many games will be prompted "Do you want to quit the game when you press the Back button to exit?" "And then there are two buttons for" OK "and" back ", in general,
Using the Android Bottom-up dialog is the best choice to block other touch events on the screen.
Using Eclipse to open the Cocos Project, under the Org.cocos2dx.lib package, there is a Cocos2dxglsurfaceview.java class with a
onkeydown function to respond to keyboard events, under Keyevent.keycode_back, add a Code Implementation dialog box pops up:
Alertdialog.builder Builder = new Alertdialog.builder (Cocos2dxactivity.getcontext ());
Builder.setmessage ("OK exit?") ");
Builder.settitle ("Hint:");
Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (dialoginterface arg0, int arg1) {
Arg0.dismiss ();
System.exit (0);
}
});
Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (dialoginterface arg0, int arg1) {
Arg0.dismiss ();
}
});
Builder.create (). Show ();
The implementation principle is very simple, more dialog box implementation can refer to the following links, http://www.oschina.net/question/157182_51417
Reprint please indicate the source, from the blog Park Hemjohn
Cocos2dx Android exit prompt dialog box