Calling JAVA class member from Native C/C++ code

后端 未结 1 385
刺人心
刺人心 2021-01-12 20:36

I\'m writing an OpenGL C/C++ application which i\'m porting to Android through Android NDK, JNI support. I\'m having difficulties executing code from JAVA callback signaled

相关标签:
1条回答
  • 2021-01-12 21:05

    You need to create global references to the class/object that you stash away. The references you're saving are local references, which can't be shared across threads and disappear when the runtime cleans up the JNI local reference stack.

    Check out the Sun/Oracle documentation for global and local references, and check out JNI methods JNIEnv::NewGlobalRef and JNIEnv::DeleteGlobalRef.

    gJClass = env->NewGlobalRef(env->FindClass( ... ));
    
    gJObjectCached = env->NewGlobalRef(obj);
    

    (Edit: Turns out you don't need global references for method IDs.)

    0 讨论(0)
提交回复
热议问题