"A little progress everyday adds up to big results"

Tuesday 26 June 2012

The power of NDK in Android

                     While developing android applications, sometimes, one might want to perform CPU intensive operations like huge number of calculations. In such cases, the time taken for performing those operations might be so high, so that the user gets frustrated. Of-course, one can run such operations as a Service ( background task ) and intimate the user on completion via notification; but, there is a better alternative in Android, called Native Devleopment Kit ( NDK ), which allows development from C/C++ instead from Java.

                       It is simply the equivalent of Java Native Interface ( JNI ) in Java. This is nothing but, calling C/C++ functions from Java. If one has a very basic knowledge of JNI, then it's not at all a matter for him/her to develop application in NDK. I faced this situation once, when I developed Speaker Recognizer application for android as a part of my internship at IIIT, Hyderabad. I had written the entire code in Java and the code executed nearly for about 40 seconds on a device with operational frequency 600 MHz. When I reported this to my project guide, Dr. Kishore S. Prahallad, he suggested me NDK.

                      I thought that C/C++ would be some 2 or 3 times faster than Java. But, to my surprise, my code executed in just 4 seconds on the same device, which is almost 10 times faster. I was wondered and realized that C and C++ are nearly 10 times faster than Java on Android devices. So, if you want to perform CPU intensive operations on android, I suggest NDK. The entire tutorial is available at this site.

1 comment: