Manipulating arrays in JNI
JNI exposes strings, classes, instance objects, and arrays as reference types. This recipe will discuss arrays in JNI.
Getting ready
You should make sure you've read the following recipes before going through this recipe:
Managing references in JNI
Manipulating classes in JNI
How to do it…
In this section, we will create a sample Android project that demonstrates how to manipulate arrays in JNI.
Create a project named
ArrayManipulation
. Set the package name ascookbook.chapter2
. Create an activity namedArrayManipulationActivity
. Under the project, create a folder namedjni
. Refer to the Loading native libraries and registering native methods recipe of this chapter for more detailed instructions.Create a file named
arraytest.c
under thejni
folder, then implement theGetArrayLengthDemo
,NewObjectArrayDemo
,NewIntArrayDemo
,GetSetObjectArrayDemo
,GetReleaseIntArrayDemo
,GetSetIntArrayRegionDemo
, andGetReleasePrimitiveArrayCriticalDemo
native methods.Modify
ArrayManipulationActivity...