This recipe covers caching in Android JNI, which can improve the performance of our native code.
You should make sure you've read the following recipes before going through this recipe:
Accessing Java static and instance fields in native code
Calling static and instance methods from native code
The following steps detail how to build a sample Android application that demonstrates caching in JNI:
Create a project named
Caching
. Set the package name ascookbook.chapter2
. Create an activity namedCachingActivity
. 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
cachingtest.c
under thejni
folder, then implement theInitIDs
,CachingFieldMethodIDDemo1
,CachingFieldMethodIDDemo2
, andCachingReferencesDemo
methods.Modify the
CachingActivity.java
file by adding code...