JNI CALL change jclass parameter or how to get job from jclass parameter

I am testing some features with Android, JNI and NDK.

I have the following JAVA class:

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class JNITest extends Activity {
    private int contador;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        contador = 0;
        TextView label = (TextView)findViewById(R.id.Text);
        label.setText(Integer.toString(contador));
    }

    public void addClick(View addButton) {
        nativeAdd(1);
        TextView label = (TextView)findViewById(R.id.Text);
        label.setText(Integer.toString(contador));
    }

    private static native void nativeAdd(int value);

    static {
        System.loadLibrary("JNITest01");
    }
}

I used javah -jnito create the header file:

#include <jni.h>
/* Header for class es_xxxxx_pruebas_JNITest */

#ifndef _JNITestNative
#define _JNITestNative
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_xxxxx_tests_JNITest
 * Method:    nativeAdd
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_com_xxxxx_tests_JNITest_nativeAdd
(JNIEnv *, jclass, jint);

#ifdef __cplusplus
}
#endif
#endif

As you can see, the second parameter is jclass .

I am wondering how can I change jclass for the jobject parameter .

I need a jobject parameter to get the value from the field of the class that calls this native function.

How to change the signature of a method? or how can I get the job from the jclass parameter?

Thank.

+3
source share
1 answer

( this), / . jclass jobject.

Java .

Java JNI, , - contador, .

+8

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


All Articles