Manipulating objects in JNI
The previous recipe shows how we can manipulate classes in Android JNI. This recipe describes how to manipulate instance objects in Android NDK programming.
Getting ready
The following recipes should be read first before going through this recipe:
Managing references in JNI
Manipulating classes in JNI
How to do it…
Now we'll create an Android project with native methods demonstrating the usage of JNI functions related to instance objects. Perform the following steps:
Create a project named
ObjectManipulation
. Set the package name ascookbook.chapter2
. Create an activity namedObjectManipulationActivity
. Under the project, create a folder namedjni
. Please refer to the Loading native libraries and registering native methods recipe in this chapter, if you want more detailed instructions.Create a file named
objecttest.c
under thejni
folder, then implement theAllocObjectDemo
,NewObjectDemo
,NewObjectADemo
,NewObjectVDemo
,GetObjectClassDemo
, andIsInstanceOfDemo
methods...