Search code examples
androidandroid-version

What version to choose?


When installing the SDK i read something about 97% of phones support Android 2.1 My question is should i, when opening a new project choose to compile it to Android 2.1? Will apps written for 2.1 work in newer version? Will the opposite work? if i develop to 4.0.3, will it work in older?

Thanks, Eric


Solution

  • My question is should i, when opening a new project choose to compile it to Android 2.1?

    What you specify as your build target ("choose to compile it to") has no direct effect on what versions of Android can run your application.

    Will apps written for 2.1 work in newer version?

    For any reasonable interpretation of the word "for", yes.

    if i develop to 4.0.3, will it work in older?

    As with Agarwal's answer, this depends on what you mean by "to".

    For example, suppose that you want to use CalendarContract. This class was added in API Level 14 (a.k.a., Android 4.0). So long as you only use CalendarContract on Android 4.0+ devices, you will be fine. If, however, you try to use CalendarContract on an older device, you will crash, because that class will not exist in the firmware.

    Hence, you can conditionally use newer APIs, so long as you ensure that you only use those newer APIs on devices running a newer version of Android. Typically, this is done via a version guard block, something like:

    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {
      // do something that requires API Level 11+ here
    }