FindClass from any thread in Android JNI

前端 未结 2 1298
孤独总比滥情好
孤独总比滥情好 2020-11-28 02:42

Android\'s JNI tips page mentions this FAQ: Why didn\'t FindClass find my class? They mention multiple solutions and the last option there is this one:

<
2条回答
  •  清歌不尽
    2020-11-28 03:28

    Try attaching your native thread to the JVM first.

    The pointer to jvm you can obtain first thing in JNI_OnLoad

    env->GetJavaVM(&jvm);
    

    Then from your native thread

    JNIEnv *env;
    jvm->AttachCurrentThread((void **)&env, NULL);
    

    Then use that env for FindClass

提交回复
热议问题