Index: libadblockplus-android/jni/JniCallbacks.cpp |
diff --git a/libadblockplus-android/jni/JniCallbacks.cpp b/libadblockplus-android/jni/JniCallbacks.cpp |
index d83a3b1e1f4329adda2d186abe199e124ad7687c..8eacee3d4c954d5cc956b18157f4cbfa8feedf0d 100644 |
--- a/libadblockplus-android/jni/JniCallbacks.cpp |
+++ b/libadblockplus-android/jni/JniCallbacks.cpp |
@@ -17,9 +17,25 @@ |
#include "JniCallbacks.h" |
+// precached in JNI_OnLoad and released in JNI_OnUnload |
+JniGlobalReference<jclass>* exceptionHandlerClass; |
+ |
+void JniCallbacks_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved) |
+{ |
+ exceptionHandlerClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("JniExceptionHandler"))); |
+} |
+ |
+void JniCallbacks_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved) |
+{ |
+ if (exceptionHandlerClass) |
+ { |
+ delete exceptionHandlerClass; |
+ exceptionHandlerClass = NULL; |
+ } |
+} |
+ |
JniCallbackBase::JniCallbackBase(JNIEnv* env, jobject callbackObject) |
- : callbackObject(new JniGlobalReference<jobject>(env, callbackObject)), |
- exceptionLoggerClass(new JniGlobalReference<jclass>(env, env->FindClass(PKG("JniExceptionHandler")))) |
+ : callbackObject(new JniGlobalReference<jobject>(env, callbackObject)) |
{ |
env->GetJavaVM(&javaVM); |
} |
@@ -31,10 +47,11 @@ JniCallbackBase::~JniCallbackBase() |
void JniCallbackBase::LogException(JNIEnv* env, jthrowable throwable) const |
{ |
- jmethodID logMethod = env->GetStaticMethodID(exceptionLoggerClass->Get(), "logException", "(Ljava/lang/Throwable;)V"); |
+ jmethodID logMethod = env->GetStaticMethodID( |
+ exceptionHandlerClass->Get(), "logException", "(Ljava/lang/Throwable;)V"); |
if (logMethod) |
{ |
- env->CallStaticVoidMethod(exceptionLoggerClass->Get(), logMethod, throwable); |
+ env->CallStaticVoidMethod(exceptionHandlerClass->Get(), logMethod, throwable); |
} |
} |