<== Chapter 3 -- Chapter 5 ==>
Chapter 4 - JNI Native Class
We need to create a Java class with the JNI to allow our Java functions to get sent down to the Native functions. Tango JNI Native Class
- Just as we did for
TangoInitializationHelper
we need to create another Java class and we will call itTangoJniNative
- The first thing we need to do is call
TangoInitializationHelper.loadTangoSharedLibrary()
and make sure we loaded the library correctly otherwise no point to continue. - We know need to load the Native C/C++ code into our application by loading it using
System.loadLibrary("tango_ndk_tutorial");
- As of now in the tutorial we have not yet wrote this code, but when we do, this is how we call it
- Take notice that these two loading of native code (Tango Library and our NDK code) takes place right away in the flow of the program
- IMPORTANT: the string
tango_ndk_tutorial
in this case must match theLOCAL_MODULE
library without thelib
prefix- This is more explain in detail in Chapter 9
- Each function we plan to call down to the native layer we need to make a
native
java function declaration- Example:
public static native void onCreate(Activity callerActivity);
- In this example we will pass the instance of the Activity object to our native code when the Activity calls
onCreate
- In this example we will pass the instance of the Activity object to our native code when the Activity calls
- Example:
- The
public static native int valueFromJNI(int myNumber);
is going to be our example of how we send the valuemyNumber
and get a int value returned - Side note, I removed the
public native String stringFromJNI();
auto generated from the boilerplate