Reputation: 3550
How can checking the build version code work on older devices?
For example, say you are on Honeycomb (v11), and you run this method:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void doSomething(){
// bla bla bla ....
...
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) // Jelly_Bean is v16)
{
addNotificationActions(builder);
}
}
How would the OS know what Build.VERSION_CODES.JELLY_BEAN is? The Android Lint checker doesn't report any errors here. Perhaps this is resolved at compile time?
Upvotes: 0
Views: 775
Reputation: 1007474
How would the OS know what Build.VERSION_CODES.JELLY_BEAN is?
Because that is a static final int
. Your compiled Java code contains the integer value, not the symbol. Hence, at runtime, the if
statement is comparing against the compiled-in integer value.
Upvotes: 2