Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does android always use the newest API to run an app?

Tags:

android

I was messing around with MeasureSpec when I came across this bit of text:

Note: On API level 17 and lower, makeMeasureSpec's implementation was such that the order of arguments did not matter and overflow in either value could impact the resulting MeasureSpec. RelativeLayout was affected by this bug. Apps targeting API levels greater than 17 will get the fixed, more strict behavior.

So that got me wondering: If I build an app for API 14 but I run it on an API 22 device will it fix the bug or will < API 17's bug still exist on the 22 device?

like image 994
Austi01101110 Avatar asked Dec 22 '15 20:12

Austi01101110


People also ask

What happens if the device is running Android 10+ API 29 +)?

If you will not be targeting Android 10 (API level 29), some of these changes might not immediately affect you. However, while you can currently use some non-SDK interfaces (depending on your app's target API level), using any non-SDK method or field always carries a high risk of breaking your app.

How does API work in Android?

The Android platform provides a framework API that applications can use to interact with the underlying Android system. The framework API consists of: A core set of packages and classes. A set of XML elements and attributes for declaring a manifest file.

What API level should I use Android?

New apps must target Android 12 (API level 31) or higher; except for Wear OS apps, which must target Android 11 (API level 30) or higher.


1 Answers

makeMeasureSpec(API 17<) method's implementation is the following:

 public static int makeMeasureSpec(int size, int mode) {
        if (sUseBrokenMakeMeasureSpec) {
            return size + mode;
        } else {
            return (size & ~MODE_MASK) | (mode & MODE_MASK);
        }
    }

As you can see it's return value is depending on the value of sUseBrokenMakeMeasureSpec which value is assigned in the View class's constructor:

  sUseBrokenMakeMeasureSpec = targetSdkVersion <= JELLY_BEAN_MR1;

So only the app's target will determine the behaviour. By doing it this way a newer system can maintain compatibility with an older app which expets the old behaviour.

like image 187
csenga Avatar answered Sep 21 '22 03:09

csenga