Android JNI方法-第二个参数是jclass还是jobject? [英] Android JNI method - Is the second parameter jclass or jobject?

查看:499
本文介绍了Android JNI方法-第二个参数是jclass还是jobject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计,

在我的Android Java代码中,我有如下声明:

In my Android Java code, I have a declaration as follows:

public class SurfacePanelNative extends SurfaceView implements SurfaceHolder.Callback {
   ...
   private static native void native_render();
}

在我的本机代码中,我将函数声明为:

In my native code, I have the function declared as:

void native_render(JNIEnv *env, jobject javaSurface) {
   ANativeWindow* window = ANativeWindow_fromSurface(env, javaSurface);
   ...
}

看网上的一些例子,似乎该函数应声明为:

Looking at some examples on the net, it appears that the function should be declared as:

void native_render(JNIEnv *env, jclass clazz) {
   ...
}

我想知道哪种声明是正确的.

I am wondering which declaration is the right one.

我认为第一个是正确的.否则,我没有足够的信息来获取javaSurface.

I am thinking the first one is the right one. Otherwise, I don't have enough information to obtain javaSurface.

如果有人可以对此有所了解,我将不胜感激.

I would appreciate it if someone can shed some light on this.

预先感谢您的帮助.

关于,
彼得

推荐答案

如果方法为static,则为jclass,否则为jobject.如果按照JNI设计人员的意图使用javah,您将始终得到正确的答案.

It is jclass if the method is static, otherwise jobject. If you use javah, as the JNI designers intended, you will always get the right answer.

这篇关于Android JNI方法-第二个参数是jclass还是jobject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆