Test our work
Now we can open fire on the Fibonacci program, run it and test it! Note: The larger the value n, the longer the program operation time, especially the recursive algorithm. We recommend that n be between 25 and 30. It should also be noted that all the things we do are in the main UI thread of the Activity. Blocking threads for a long time will cause the program's no response (not responding: ANR) error, see Figure 6-9. As an exercise, you may think of adding AsyncTask to the actual computation, as described in "AsyncTask" On page 67th, to prevent the main thread from being congested.
After several rounds of tests, you may find that the local version of the algorithm is faster than the Java implementation algorithm by an order of magnitude (see Figure 15-1 ).
--------------------------------
Fibonacci
--------------------------------
--------------
FibActivity
--------------
--------------
Java local library (fig. java)
--------------
Load Database
--------------
Local Library (fiber Lib. so)
--------------
--------------------------------
Dalvik Virtual Machine
--------------------------------
Figure 15-1. Maid of 33
These results should provide enough reason for you to consider Porting some highly computational code to the local code. NDK makes it easier to integrate local code into your program.
Summary
Starting from the ginger pie (gingerbread) version (2.3), NDK already supports local activity. You can use C to create the entire activity and follow the lifecycle rules of the activity, this topic is discussed in "Activity lifecycle" on page 1. This makes Game Development in Android much easier.
Linc note:
The translation in this chapter is over, and I will upload this applet later. I hope everyone will try it on their own. It's quite easy to build the NDK environment. Please refer to my related blog.
This book is very good. I hope you can check it out too. Original Website:
Http://ofps.oreilly.com/titles/9781449390501/NDK.html