Managing references in JNI

JNI exposes strings, classes, instance objects, and arrays as reference types. The previous recipe introduces the string type. This recipe will cover reference management and the subsequent three recipes will discuss class, object, and arrays respectively.

How to do it…

The following steps create a sample Android project that illustrates reference management in JNI:

  1. Create a project named ManagingReference. Set the package name as cookbook.chapter2. Create an activity named ManagingReferenceActivity. Under the project, create a folder named jni. Refer to the Loading native libraries and registering native methods recipe in this chapter, if you want more detailed instructions.
  2. Create a file named referencetest.c under the ...

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.