Ok, so I did some more digging, it seems that I was wrong about the
passed in JNIEnv* being incorrect. But the problem remains. First let
me show what I did.
In java_callback() I added some code, so that now it looks like this:
void java_callback(JNIEnv* env, ... , jstring myString) {
JNIEnv* localEnv;
jint status = gspGlue->vm->GetEnv((void**) &localEnv,
JNI_VERSION_1_6);
if (status == 0) {
LOGD("determined local env: %p (vs arg env: %p)",
localEnv, env);
env = localEnv;
} else {
LOGW("GetEnv failed, status: 0x%x", status);
}
mutex_acquire();
// -- note that I'm using local JNIEnv*, rather than global
env->GetStringUTFChars(jstrItemID, NULL);
mutex_release();
}
and indeed, the env that is passed in is equal to localEnv that is
obtained from the vm for both UI thread and auxiliary thread. However,
when called from the auxiliary thread GetStringUTFChars triggers an
error message:
05-22 14:45:56.790: D/Purchase(29492): determined local env: 0x271c8d0
(vs arg env: 0x271c8d0)
...
05-22 14:45:56.790: E/dalvikvm(29492): JNI ERROR: env->self != thread-
self (0x1f31830 vs. 0x2730d30); auto-correcting
It seems that dalvik wants me to use UI thread's env.. thoughts?