Cocos2d-x C++调用Android弹出提示框(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-18 20:55 点击:次
p> Log.d("CocosDemoAndroid", String.valueOf(msg.obj)); //获取到Handler传递的参数数据
p> AlertDialog.Builder builder=new Builder(mContext);
p> builder.setTitle("C++调用Android");
p> builder.setMessage("C++调用Android显示弹出框");
p> builder.show();
p> }
p> super.handleMessage(msg);
p> }
p> };
p>
p> @Override
p> protected void onCreate(Bundle savedInstanceState) {
p> super.onCreate(savedInstanceState);
p> mContext=MainActivity.this;
p> }
p>
p>
p>
p> @Override
p> public boolean onCreateOptionsMenu(Menu menu) {
p> // Inflate the menu; this adds items to the action bar if it is present.
p> getMenuInflater().inflate(R.menu.main, menu);
p> return true;
p> }
p>
p>
p> public static void showMessage()
p> {
p> Log.d("showMessage", "showMessage");
p> Message msg=new Message();
p> msg.what=SHOW_MESSAGE;
p> msg.obj="showmessage demos"; //可以传递参数
p> handler.sendMessage(msg);
p> }
p>
p> public native int InitJni();
p>
p> static
p> {
p> System.loadLibrary("CocosDemo");
p> }
p>
p>}
p>对于Android:
p>
p>为什么要使用Handle sendMessage() ??
p>
p>因为如果直接在showMessage中弹出提示框,会崩溃提示 Can't create handle inside thread that has not called Looper.prepare()
p>
p>
p>
p>再附上的Android.mk文件:
p>
p>[cpp]
p>LOCAL_PATH := $(call my-dir)
p>
p>RAKNET_LIB_PATH := ../../../../RakNet_PC-4.08/Android/obj/local/$(TARGET_ARCH_ABI)/libRakNet.a
p>
p>$(call import-add-path, $(Cocos2d)) \
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>