The previous recipe discusses that Android JNI supports three different kinds of references. The references are used to access the reference data types, including string, class, instance object, and array. This recipe focuses on class manipulations in Android JNI.
The Managing References in NDK recipe should be read first before going through this recipe.
The following steps describe how to build a sample Android application that illustrates class manipulation in JNI:
Create a project named
ClassManipulation
. Set the package name ascookbook.chapter2
. Create an activity namedClassManipulationActivity
. Under the project, create a folder namedjni
. Refer to the Loading native libraries and registering native methods recipe of this chapter if you want more detailed instructions.Create a file named
classtest.c
under thejni
folder, then implement thefindClassDemo
,findClassDemo2
,GetSuperclassDemo
, andIsAssignableFromDemo
methods. We can...