Android: Java, C or C++?

26,148

Solution 1

The article you link to has good information. It also links to http://developer.android.com/sdk/ndk/overview.html which says:

The NDK will not benefit most applications. As a developer, you need to balance its benefits against its drawbacks; notably, using native code does not result in an automatic performance increase, but always increases application complexity. In general, you should only use native code if it is essential to your application, not just because you prefer to program in C/C++.

Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on. Simply re-coding a method to run in C usually does not result in a large performance increase. When examining whether or not you should develop in native code, think about your requirements and see if the Android framework APIs provide the functionality that you need. The NDK can, however, can be an effective way to reuse a large corpus of existing C/C++ code.

Solution 2

Android is Linux underneath so you can run any language on it. I have run Perl scripts on an Android phone for fun. From a practical, application development point-of-view, Google's implementation of Java running on Dalvik would be the typical route to take.

Solution 3

Java always allows you to call "native code" components. However, you want to avoid them if possible because they can introduce subtle bugs and platform dependencies into your code.

I don't believe you can code a whole application for Android in C/C++ however -- you must have a Java wrapper at the very least.

Solution 4

This is good question, AFAIK, c or c++ comes into picture when you really want to program something core dalvik feature than using Android API as specified you question, something like sensor related features or hardware.

If you want build app using API, it will be mostly in Java/XML.

Solution 5

Re-writing one of those "self-contained, CPU-intensive operations that don't allocate much memory" in C may improve the performance/battery life by a factor of 17 according to this investigation. This article finds that running CCTOOLS Fortran is even quicker. So alternative languages are well worth considering.

Share:
26,148
Evgenij Reznik
Author by

Evgenij Reznik

Updated on November 25, 2020

Comments

  • Evgenij Reznik
    Evgenij Reznik over 3 years

    I wrote some simple apps in Android using Java.
    But later I found this:

    It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++. (Source)

    How is it related to this:

    Android applications are written in the Java programming language. (Source)

    Are all three languages possible?
    Sorry for the dumb question.