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 ...

Get Android Native Development Kit Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.