Game Development Reference
In-Depth Information
This creates the NDK library named ch02 as well as the Android Native directory jni/
(see Figure 2-6 ).
Figure 2-6. Android native support directories
The jni folder contains the native code, including the following (see Figure 2-6 ):
ch02.cpp : This is the main library code. It contains all the necessary JNI
system calls to cascade information back and forth between Android
and C.
Android.mk : This is the Android makefile used to build the native library
which will be stored in libs/ .
Let's look at the files in more detail to understand what they do, starting from the top with
the Java main activity and its companion native interface. These two work together with the
native library. Finally, you glue all the pieces together at compilation time.
Main Activity
The file ch02.project.MainActivity.java is created by the wizard, and it is the entry point
to the phone application. Listing 2-1 shows the code for this file. There are some remarkable
things to note about this file.
As you should know, when the application starts, the method onCreate(Bundle
savedInstanceState) is invoked by Android, which loads the native library using System.
loadLibrary(name) .
Search WWH ::




Custom Search