Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In most of the cases it is only necessary to transfer simple data structures. For this purpose it is fairly enough to only work with static methods. The ARES Touch SDK provides a handful helper classes to avoid working directly with the JNI interfaces and Java environment. The utility class is called FxJavaUtils and provides a large set of classes. These are the steps to address a simple data transfer between the host app and the C++ app part and vice versa.

...

1.1 Create a Java class and add a public native static method

public static native RETURNTYPE JAVA_TO_CPP( PARAMS );

The RETURNTYPE as well as the PARAMS must be declared with Java known data types. The method name JAVA_TO_CPP does not need to contain characters like _ , may be just JAVATOCPP.

...

Declare your matching C++ method and make sure it matches exactly in RETURNTYPE, PARAMS and name JAVA_TO_CPP else you will more likely face an unsatisfied linker error on runtime. Keep an eye that PATH_TO_YOUR_CLASSexactly refers to the location of your Java class/file based on the root “src/main/java” folder.
e.g.: …/YOUR_ANDROID_PROJECT/src/main/java/PATH_TO_YOUR_CLASS
e.g.: …/YOUR_ANDROID_PROJECT/src/main/java/com/domain/folder/CLASSNAME
e.g.: Java_com_domain_folder_CLASSNAME_JAVA_TO_CPP()

Status
colourYellow
titleC++

...

Code Block
JNIEXPORT RETURNTYPE JNICALL Java_PATH_TO_YOUR_CLASS_JAVA_TO_CPP( JNIEnv * env, jclass clazz [, PARAMS ...] )
{
    // RETURNTYPE
    // void just return; or ignore
    // else return RETURNTYPE;
}

In the case you specify PARAMS and RETURNTYPE please declare the data types in the JNI matching pairs.

...

1.4 Return values back from C++ to Java

Status
titleJAVA
Status
colourYellow
titleC++

...