Accessing Java static and instance fields in the native code

We have demonstrated how to pass parameters of different types to native methods and return data back to Java. This is not the only way of sharing data between the native code and Java code. This recipe covers another method—accessing Java fields from the native code.

Getting ready

We're going to cover how to access Java fields of different types, including primitive types, strings, instance objects, and arrays. The following recipes should be read first before reading this recipe:

  • Passing parameters and receiving returns in primitive types
  • Manipulating strings in JNI
  • Manipulating classes in JNI
  • Manipulating objects in JNI
  • Manipulating arrays in JNI

Readers are also expected to be familiar ...

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.