You can choose how many classes to create in Java and how you spread the code through the application (so there are many ways of achieveing the same result);
the only couple of RULES to keep in mind when working with JNI are these:
If you want to call a native (C++) method from a Java class:
1. the native function must be declared as "native" within tthe same class (e.g. "private void native myNativeFunction();) ,
2. and the function name in native code must "reflect" the name of the Java class from which the method is called, e.g.:
So, suppose you have a class called MyClass in a package called "com.qualcomm" (so the full class name is "com.qualcomm.MyClass") and in this class you have declared a "private void native myNativeMethod()", then the C++ function will have to be named like that:
JNIEXPORT void JNICALL Java_com_qualcomm_MyClass_myNativeMethod (JNIEnv* env, jobject javaObject) { /* some code */ }
NOTE that the jobject javaObject argument represents the MyClass instance that is invoking your native method.
Second rule: for what concerns calling Java methods from a native C++ code, you need to use the CallVoidMethod (or CallIntMethod, CallFloatMethod, depending on the return type) by passing the javaObject that represents a certain Java class instance (for instance an instance of com.qualcomm.MyClass),;
consider the following example taken from Dominoes.cpp (see displayMessage() method):
jstring js = javaEnv->NewStringUTF(message);
jmethodID method = javaEnv->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
javaEnv->CallVoidMethod(javaObj, method, js);
As you can see here we invoke the Java method "displayMessage()" by using CallVoidMethod and by passing "javaObj" as argument; in this example, the javaClass represents the DominoesRenderer class and the javaObject is an instance of DominoesRenderer in this case because those two variables have been initialized in the Java_com_qualcomm_QCARSamples_Dominoes_DominoesRenderer_initNativeCallback,
but it could have been a different class as well, if we initialized those somewhere else; so it really depends how you want to structure your application (e.g. spreading into multiple classes or just in a few).
I hope this can be of help;
I can also suggest to have a look at the JNI tutorial at:
http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html
This can help get you started with all sort of JNI acrobacies :-)
Hi Warren, is this related to Android or to Unity ?
if that's about Unity, please post it in the Unity section of the Forum.