Calling static and instance methods from the native code
The previous recipe covers how to access Java fields in NDK. Besides fields, a Java class also has methods. This recipe focuses on calling static and instance methods from JNI.
Getting ready
The code examples require a basic understanding of the JNI primitive types, strings, classes, and instance objects. It is better to make sure you have read the following recipes before going through this recipe:
Passing parameters and receiving returns in primitive types
Manipulating strings in JNI
Manipulating classes in JNI
Manipulating objects in JNI
Accessing Java static and instance fields in native code
Readers are also expected to be familiar with Java reflection API.
How to do it…
The following steps can be followed to create a sample Android project that illustrates how to call static and instance methods from the native code:
Create a project named
CallingMethods
. Set the package name ascookbook.chapter2
. Create an activity namedCallingMethodsActivity...