Learning Android Chapter 3 NDK translation III

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.