JNI_Onload的实现

http://stackoverflow.com/questions/2453692/jni-loses-reference-to-native-methods


void onChange(JNIEnv *, jobject, jfloat);


JNINativeMethod methods[] = {
{"onChange", "(F)V", (void *)onChange}
};


jint JNI_OnLoad(JavaVM *jvm, void *reserved) {
JNIEnv *env;
(*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_4);


jclass inheritance = (*env)->FindClass(env, "Inheritance");
(*env)->RegisterNatives(env, inheritance, methods, 1);


jobject o_inheritance = (*env)->NewObject(env, inheritance, (*env)->GetMethodID(env, inheritance, "<init>", "()V"));
jclass provider = (*env)->FindClass(env, "Provider");
jobject o_provider = (*env)->NewObject(env, provider, (*env)->GetMethodID(env, provider, "<init>", "()V"));


(*env)->CallVoidMethod(env, o_provider, (*env)->GetMethodID(env, provider, "registerChange", "(LListener;)V"), o_inheritance);
(*env)->CallVoidMethod(env, o_provider, (*env)->GetMethodID(env, provider, "sendMsg", "()V"));


return JNI_VERSION_1_4;
}


void onChange(JNIEnv *env, jobject self, jfloat f) {
printf("[C] %f\n", f);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值