I'm trying to call java static method from c++ on sigaction handler,but the java method dose not work. CallStaticVoidMethod return success but the java code has not been execute.
bool Init( JNIEnv* env,jobject obj,const std::string &functionName)
{
LOGE("Init 1");
//jobject is the java static method object
_j_class_ = (jclass)env->NewGlobalRef((jobject)env->GetObjectClass(obj));
if(_j_class_ == 0)
{
LOGE("className not found! _j_class_ == 0");
return false;
}
_j_method_ = env->GetStaticMethodID(_j_class_, functionName.c_str(),"(Ljava/lang/String;)V");
if(_j_method_ == 0)
{
LOGE("functionName:%s,_j_method_ == 0",functionName.c_str());
return false;
}
LOGE("functionName:%s,_j_method_ success",functionName.c_str());
return m_is_inited = true;
}
//when native crash occurs,will call this method
void InvokeToJava(const char *pErrorString)
{
LOGE("NativeCrashHelper::InvokeToJava Start.");
m_is_inited = false;
JNIEnv *pEnv = NULL;
const int nRet = JNI_Object::beforeCallToJava(&pEnv); //init the pEnv
if(nRet == -1)
{
LOGE("nRet == -1");
return;
}
if(_j_class_ == 0)
{
LOGE("_j_class_ == 0");
return ;
}
if(_j_method_ == 0)
{
LOGE("_j_method_ == 0");
return;
}
jstring err = 0;
LOGE("InvokeToJava Convert Error String.");
StringFunction::C2J(pEnv,pErrorString,err);
LOGE("InvokeToJava CallStaticVoidMethod");
pEnv->CallStaticVoidMethod(_j_class_,_j_method_,err);
LOGE("InvokeToJava CallStaticVoidMethod Finished!");
pEnv->DeleteLocalRef(err);
JNI_Object::afterCallToJava(nRet);
LOGE("NativeCrashHelper::InvokeToJava Finished.");
}
Here is the java method:
public static void crashHelperNotify(String nativeCrashInfo){
Log.e("NativeCrashHelper","crashHelperNotify: ");
//if (s_CallBackMethod != null) {
// s_CallBackMethod.invoke(null, nativeCrashInfo);
//}
}
And the logcat is show below:
// those log seems that call java method success, I can not figure out why the java method dose't work
_jni_log: Native_SigAction //zz
_jni_log: Native_SigAction: Reset Sigaction. //zz
_jni_log: Native_SigAction InvokeToJava :signal : 11,
_jni_log: NativeCrashHelper::InvokeToJava Start. //zz
_jni_log: InvokeToJava Convert Error String. //zz
_jni_log: InvokeToJava CallStaticVoidMethod //zz
_jni_log: InvokeToJava CallStaticVoidMethod Finished! //should print java log here
_jni_log: NativeCrashHelper::InvokeToJava Finished. //zz
_jni_log: Native_SigAction Finished! //zz
I search a lot but can not find any help