Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

versioning - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...