Java code can pass parameters to native methods and receive the processing results returned. This recipe walks through how to pass parameters and receive returns in primitive types.
You should have built at least one Android application with native code before reading this recipe. If you haven't done so, please read the Writing a Hello NDK program recipe in Chapter 1, Hello NDK first.
The following steps create a sample Android application with native methods receiving input parameters from the Java code and returning the processing result back:
Create a project named
PassingPrimitive
. Set the package name ascookbook.chapter2
. Create an activity namedPassingPrimitiveActivity
. Under this 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.Add a file named
primitive.c
under thejni
folder...