[Android] Don't attach the same thread twice to the JVM

ANativeActivity_onCreate is called by NaviteActivity from Java (which is the main thread). Thus, this thread is already attached to the JVM.
This commit is contained in:
Jonathan De Wachter 2014-03-11 21:10:11 +01:00
parent 84bd8c6c5b
commit 83306e72a2

View File

@ -129,26 +129,10 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
// //
// With libname being the library name such as "jpeg". // With libname being the library name such as "jpeg".
// Initialize JNI // Retrieve JNI environment and JVM instance
jint lResult;
jint lFlags = 0;
JavaVM* lJavaVM = activity->vm; JavaVM* lJavaVM = activity->vm;
JNIEnv* lJNIEnv = activity->env; JNIEnv* lJNIEnv = activity->env;
JavaVMAttachArgs lJavaVMAttachArgs;
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
lJavaVMAttachArgs.name = "NativeThread";
lJavaVMAttachArgs.group = NULL;
// Attach the current thread to the JAva virtual machine
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
if (lResult == JNI_ERR) {
LOGE("Couldn't attach the current thread to the Java virtual machine");
exit(1);
}
// Retrieve the NativeActivity // Retrieve the NativeActivity
jobject ObjectNativeActivity = activity->clazz; jobject ObjectNativeActivity = activity->clazz;
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity); jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity);
@ -188,9 +172,6 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
std::string libName = getLibraryName(lJNIEnv, ObjectActivityInfo); std::string libName = getLibraryName(lJNIEnv, ObjectActivityInfo);
void* handle = loadLibrary(libName.c_str(), lJNIEnv, ObjectActivityInfo); void* handle = loadLibrary(libName.c_str(), lJNIEnv, ObjectActivityInfo);
// todo: should we detach the current thread ? because if we do, it
// crashes (lJavaVM->DetachCurrentThread();)
// Call the original ANativeActivity_onCreate function // Call the original ANativeActivity_onCreate function
activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate"); activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");