Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Android version code constants work with older versions?

Can I use Android version code constants with older Android runtimes? For instance,

if (android.os.Build.VERSION.SDK_INT >= 
   android.os.Build.VERSION_CODES.HONEYCOMB) ...

would this run without crash on old devices running Android operating system before HONEYCOMB when this constant has been first defined? Assuming we compile it with recent enough SDK?

like image 951
Audrius Meškauskas Avatar asked Feb 17 '14 19:02

Audrius Meškauskas


People also ask

What is version code and version name?

The version code is an incremental integer value that represents the version of the application code. The version name is a string value that represents the “friendly” version name displayed to the users.

What is the minimum supported Android version?

From now on, the lowest level of Android we'll be supporting is Android 6 (Marshmallow).


2 Answers

Yes, this will work.

The reason for this is that android.os.Build.VERSION_CODES.HONEYCOMB is an int. android.os.Build.VERSION_CODES.HONEYCOMB is just an alias (the int equals 11) for 11, as can be seen in an IDE such as Eclipse:

int android.os.Build.VERSION_CODES.HONEYCOMB = 11 [0xb]

So this will work as it'll just check if the android.os.Build.VERSION.SDK_INT is greater than or equal to 11.

like image 114
hichris123 Avatar answered Oct 16 '22 06:10

hichris123


Yes you can. It works because the int values are static final. The compiler will inline them into the bytecode at compile time. No symbol import is required at runtime.

like image 20
laalto Avatar answered Oct 16 '22 05:10

laalto