(备份)java 弹出退出提示框 lua调用
2015-08-27 14:16
330 查看
</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(); } }); } }
lua调用:
function exitGame() if device.platform == "android" then luaj.callStaticMethod("org/cocos2dx/lua/AppActivity", "exitGame", {},"()V") end end
用到的地方,直接调用exitGame()即可
相关文章推荐
- lua单链表简单实现
- 第20章 Lua脚本
- Lua Table 操作
- lua队列实现
- lua单链表实现
- lua中os.clock()为何会返回负值
- Decoda编译方法
- Step By Step(Lua目录)
- Lua学习笔记--C调用Lua
- Mac下Lua Sublime Text3 开发环境搭建
- Lua--table的遍历
- Lua学习笔记--table
- lua中查找表的过程已经(以及对元表和__index方法的理解)
- Lua继承原理(如何实现面向对象)
- SourceInsight 增加对Lua语言的支持
- lua中函数为什么有时候可以省略”()”?
- Lua学习笔记--函数初探
- lua coco2d android quick-3.5
- Lua学习笔记--基本语法规则&控制流语句
- Lua和C++交互