</pre><p><span style="color:#990000;">java端如下</span></p><p><pre name="code" class="java">public class AppActivity extends Cocos2dxActivity {
static private AppActivity s_instance;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
s_instance = this;
……
}
……
public static void exitGame() {
s_instance.runOnUiThread(new Runnable() {
@SuppressWarnings("deprecation")
@Override
public void run() {
/**监听对话框里面的button点击事件*/
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case AlertDialog.BUTTON_POSITIVE:// "确认"按钮退出程序
android.os.Process.killProcess(android.os.Process.myPid());
break;
case AlertDialog.BUTTON_NEGATIVE:// "取消"第二个按钮取消对话框
break;
default:
break;
}
}
};
// 创建退出对话框
AlertDialog isExit = new AlertDialog.Builder(s_instance).create();
// 设置对话框标题
isExit.setTitle("提示");
// 设置对话框消息
isExit.setMessage("确定要退出吗");
// 添加选择按钮并注册监听
isExit.setButton("确定", listener);
isExit.setButton2("取消", listener);
// 显示对话框
isExit.show();
}
});
}
}
function exitGame()
if device.platform == "android" then
luaj.callStaticMethod("org/cocos2dx/lua/AppActivity", "exitGame", {},"()V")
end
end
用到的地方,直接调用exitGame()即可