Reputation: 7642
I'm new to Android programming. I want to write some custom animation which is supported only in the latest Android 5.0 (API 21). I would like to know what is the best/recommended way to write SDK specific code.
if (Build.VERSION.SDK_INT >= SOME_SDK_VERSION) {
// write api specific code here?
}
Is the above method the right way to do it? For example, if there are multiple SDK specific API calls, should I wrap everything in an above format?
Upvotes: 1
Views: 1840
Reputation: 38595
Yes, you can always do this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// code for Lollipop and later
}
This will work even on pre-Lollipop devices (because the version code is inlined at compile time and SDK_INT
is not).
Upvotes: 8