When you pass Env->callstaticvoidmethod to callback in JNI, you always hang up.
The reason is that jnienv is thread-dependent and can only be used in the corresponding created thread
The JVM is process-dependent and can be used by the JVM to get thread-related jnienv.
Initialize as follows
static void
Com_test_player_native_init (jnienv *env)
{
Jclass Clazz;
Clazz = Env->findclass ("Com/test/player");
if (clazz = = NULL) {
Return
}
Fields.post_event = Env->getstaticmethodid (Clazz, "postevent",
"(Ljava/lang/object;iiiljava/lang/object;) V");
if (fields.post_event = = NULL) {
Return
}
Set the virtual machine.
ENV->GETJAVAVM (& (FIELDS.PJVM));
}
Using env
void postevent (int msg)
{
JNIEnv *env;
Fields.pjvm->attachcurrentthread (&env, NULL);
Env->callstaticvoidmethod (MClass, fields.post_event, Mobject, msg);
Fields.pjvm->detachcurrentthread ();
}
Android JNI uses jnienv across threads