I want to do something when the cocos2dx is in onresume state
Application::applicationWillEnterForeground() ?
I want to create a sprite during Application::applicationWillEnterForeground() using the code below
const char * HelloWorld::addSprite(){
JavaVM *jvm; //this is important to avoid threading errors
thisEnv->GetJavaVM(&jvm); //this is important to avoid threading errors
jvm->AttachCurrentThread(&thisEnv, 0); //this is important to avoid threading errors
//jstring jstr = thisEnv->NewStringUTF("From jni");
jclass cls = thisEnv->GetObjectClass(thisObj);
jmethodID method = thisEnv->GetMethodID(cls, "getPath","()Ljava/lang/String;");
jstring result = (jstring)thisEnv->CallObjectMethod(thisObj, method);
// call the sayHello() method
const char * string=thisEnv->GetStringUTFChars(result, 0);
//CCMessageBox(string,"Alert");
//if(string!=NULL){
CCSprite* person = CCSprite::create(string);
//person->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
person->setAnchorPoint(ccp(0, -.75));
person->setPosition(ccp(0,0));
this->addChild(person,204);
return string;
}
then this is how i call the method in applicationWillEnterForeground()
void AppDelegate::applicationWillEnterForeground(){
HelloWorld hello;
hello.addSprite();
}
in doing the above code I got an exception
call to OpenGL ES API with no current context (logged once per thread)