As pointed out by this question and a bit of testing I did, android.os.Build.VERSION_CODES
work on platform versions that are older than the platform version of the VERSION_CODE
you are using.
E.g. this:
android.os.Build.VERSION_CODES.HONEYCOMB
Also works on Gingerbread devices, although Honecomb was released after Gingerbread.
This seems to only work if your target SDK is later than the VERSION_CODE you use, which leads me to the assumtion that the version code somehow get compiled into the APK from the target SDK.
Now, my question is:
How does that work? According to the accepted answer of the linked question, this works via an int alias, but Java does not seem to have support for aliases.
It's a compile-time constant that gets inlined in the generated bytecode. Because of that, the symbol does not need to be resolved at runtime.
A compile-time constant is something that is
final
String
The VERSION_CODES
are all static final ints, meaning that when you build your app, all of the variables are just replaced with numbers. Basically, if you look in your app's bytecode after compilation, you will likely see any references to the VERSION_CODES
just replaced with the actual int
that each version code variable represents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With