Folks,
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.
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.
Thank you in advance for your help.
Regards,
Peter
jobject thiz means the this in java class. Sometimes if you create a static native method like this. void Java_MyClass_method1 (JNIEnv *, jclass); jclass means the class itself. Follow this answer to receive notifications.
jclass is a reference to the current class. if the JNI function arguments have jobject , then this JNI function corresponds to the Java side instance method (the native methods declared without "static").
JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).
JClass is typically implemented in one of two ways: by wrapping a java. lang. Class or by parsing a source file directly with a tool such as javadoc or javelin. If a JClass represents an inner class, its getParent() method returns the outer class. Otherwise, it returns the containing package.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With