Chapter 3. Interfacing Java and C/C++ with JNI
Android is inseparable from Java. Its kernel and core libraries are native, but the Android application framework is almost entirely written in Java or at least wrapped inside a thin layer of Java. Do not expect to build your Android GUI directly in C/C++! Most APIs are available only from Java. At best, we can hide it under the cover... Thus, native C/C++ code on Android would be nonsense if it was not possible to tie Java and C/C++ together.
This role is devoted to the Java Native Interface API. JNI is a standardized specification allowing Java to call native code and native code to call Java back. It is a two-way bridge between the Java and native side; the only way to inject the power of C/C++ into your Java application.
Thanks to JNI, one can call C/C++ functions from Java like any Java method, passing Java primitives or objects as parameters and receiving them as result of native calls. In turn, native code can access, inspect...