1. jni回调java成功一次之后也很简单的。(以hello-jni为原型修改)
2. HelloJni.java 中的代码
-
public void onCreate(Bundle savedInstanceState)
-
{
-
super.onCreate(savedInstanceState);
-
TextView tv = new TextView(this);
-
tv.setText( stringFromJNI() );
-
setContentView(tv);
-
-
nativeCallBack();
-
}
-
-
public void callback_func(int notify_id, int param)
-
{
-
Log.i("JNICallback","notify_id="+notify_id+";param="+param);
-
}
-
public native void nativeCallBack();
3. hello-jni.c中的代码
-
void Java_com_example_hellojni_HelloJni_nativeCallBack( JNIEnv* env, jobject thiz )
-
{
-
LOGI("jni callback (0)");
-
jclass cls = (*env)->GetObjectClass(env, thiz);
-
jmethodID cb_method = (*env)->GetMethodID(env, cls,"callback_func","(II)V");
-
(*env)->CallVoidMethod(env, thiz,cb_method,5,10);
-
LOGI("jni callback (1)");
-
return ;
-
}
[参考]
阅读(5749) | 评论(0) | 转发(0) |