Android Cocos2d-x 3.7: how to get Application Context in cocos2d-x? -
i use android code cocos2dx call encountered problem. not call in android cocos2dx context, i'm not sure whether there problem following code, , following way need call in android , errors such calls occur .
void admasterconvsdk::admasterinitial(std::string appid) { jnimethodinfo methodinfo; if (jnihelper::getstaticmethodinfo(methodinfo, "com/admaster/square/api/convmobisdk", "initial", "(landroid/content/context;ljava/lang/string;)v")) { jstring appid = methodinfo.env->newstringutf(appid.c_str()); jclass cl = methodinfo.env->findclass("org/cocos2dx/lib/cocos2dxactivity"); jmethodid methodcontext = methodinfo.env->getstaticmethodid(cl,"getcontext","()landroid/content/context"); jobject context = methodinfo.env->callstaticobjectmethod(cl,methodcontext); methodinfo.env->callstaticvoidmethod(methodinfo.classid,methodinfo.methodid,context,appid); } else { log("error"); } }
android code:
public static void initial(context context, string m2id) { convmobiinstance adjustinstance = convmobisdk.getdefaultinstance(); adjustinstance.initial(context, m2id); }
error:
08-31 17:03:07.083: a/libc(22452): fatal signal 11 (sigsegv) @ 0x0000001c (code=1), thread 22470 (thread-38567)
has been studied long time , hope have appeared answer question , in advance .
you c++ code run in glthread bug java code need run in uithread ,so if call java method c++,you need make java code run in ui thread, change java code:
public static void initial(final context context, final string m2id) { ((activity)context).runonuithread(new thread(){ @override public void run() { // todo auto-generated method stub super.run(); convmobiinstance adjustinstance = convmobisdk.getdefaultinstance(); adjustinstance.initial(context, m2id); } }); }
Comments
Post a Comment