Creating and terminating native threads at Android NDK
This recipe discusses how to create and terminate native threads at Android NDK.
Getting ready…
Readers are expected to know how to create an Android NDK project. We can refer to the Writing a Hello NDK program recipe in Chapter 1, Hello NDK, for detailed instructions.
How to do it...
The following steps describe how to create a simple Android application with multiple native threads:
Create an Android application named
NativeThreadsCreation
. Set the package name ascookbook.chapter6.nativethreadscreation
. Refer to the Loading native libraries and registering native methods recipe in Chapter 2, Java Native Interface for more detailed instructions.Right-click on the project NativeThreadsCreation, select Android Tools | Add Native Support.
Add a Java file named
MainActivity.java
under packagecookbook.chapter6.nativethreadscreation
. This Java file simply loads the native libraryNativeThreadsCreation
and calls the nativejni_start_threads
method...