Android JNI method is jclass or jobject second parameter?

People,

In my Android Java code, I have an ad like this:

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

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

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

After looking at a few examples on the network, it seems that the function should be declared as:

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

I am wondering which declaration is correct.

I think the first one is correct. Otherwise, I do not have enough information to get javaSurface.

I would appreciate it if someone could shed light on this.

Thank you in advance for your help.

Yours faithfully,
Peter

+6
source share
1 answer

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

+8
source

Source: https://habr.com/ru/post/954028/


All Articles