diff --git a/src/api-impl-jni/android_os_MessageQueue.c b/src/api-impl-jni/android_os_MessageQueue.c index 1be0e383..0c815a8b 100644 --- a/src/api-impl-jni/android_os_MessageQueue.c +++ b/src/api-impl-jni/android_os_MessageQueue.c @@ -27,11 +27,10 @@ static GThread *main_thread_id; void prepare_main_looper(JNIEnv* env) { main_thread_id = g_thread_self(); - jclass class = (*env)->FindClass(env, "android/os/Looper"); - (*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "prepareMainLooper", "()V")); + (*env)->CallStaticVoidMethod(env, handle_cache.looper.class, handle_cache.looper.prepareMainLooper); if((*env)->ExceptionCheck(env)) (*env)->ExceptionDescribe(env); - (*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "loop", "()V")); + (*env)->CallStaticVoidMethod(env, handle_cache.looper.class, handle_cache.looper.loop); if((*env)->ExceptionCheck(env)) (*env)->ExceptionDescribe(env); } @@ -62,8 +61,7 @@ static gboolean glib_context_callback(gpointer user_data) { JNIEnv *env; (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6); - jclass class = (*env)->FindClass(env, "android/os/Looper"); - (*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "loop", "()V")); + (*env)->CallStaticVoidMethod(env, handle_cache.looper.class, handle_cache.looper.loop); if((*env)->ExceptionCheck(env)) (*env)->ExceptionDescribe(env); diff --git a/src/api-impl-jni/util.c b/src/api-impl-jni/util.c index 96d3a67a..1a0eced8 100644 --- a/src/api-impl-jni/util.c +++ b/src/api-impl-jni/util.c @@ -137,6 +137,9 @@ void set_up_handle_cache(JNIEnv *env) handle_cache.application.class = _REF((*env)->FindClass(env, "android/app/Application")); handle_cache.application.get_app_icon_path = _METHOD(handle_cache.application.class, "get_app_icon_path", "()Ljava/lang/String;"); + handle_cache.looper.class = _REF((*env)->FindClass(env, "android/os/Looper")); + handle_cache.looper.loop = _STATIC_METHOD(handle_cache.looper.class, "loop", "()V"); + handle_cache.looper.prepareMainLooper = _STATIC_METHOD(handle_cache.looper.class, "prepareMainLooper", "()V"); } void extract_from_apk(const char *path, const char *target) { diff --git a/src/api-impl-jni/util.h b/src/api-impl-jni/util.h index 02a2bb5a..540cb746 100644 --- a/src/api-impl-jni/util.h +++ b/src/api-impl-jni/util.h @@ -94,6 +94,11 @@ struct handle_cache { jclass class; jmethodID get_app_icon_path; } application; + struct { + jclass class; + jmethodID loop; + jmethodID prepareMainLooper; + } looper; }; extern struct handle_cache handle_cache;