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:
Create a project named
ManagingReference
. Set the package name ascookbook.chapter2
. Create an activity namedManagingReferenceActivity
. Under the project, create a folder namedjni
. Refer to the Loading native libraries and registering native methods recipe in this chapter, if you want more detailed instructions.Create a file named
referencetest.c
under thejni
folder, then implement thelocalReference
,globalReference
,weakReference
, andreferenceAssignmentAndNew
methods. This is shown in the following code snippet:JNIEXPORT void JNICALL Java_cookbook_chapter2_ManagingReferenceActivity_localReference...