Using new sdk methods on devices running older sdks?

by Mark Murphy » Tue, 22 Dec 2009 01:47:43 GMT

Sponsored Links

I wouldn't do:

if (Build.VERSION.SDK.equals("5")) {

Instead, parse it to an integer and do a >=5 comparison. After all, most
DROIDs are now on API 6 (i.e., Android 2.0.1). And, once you drop older
SDK support, you can use SDK_INT and skip the parse step.

If you are going to make the request a lot, you might consider having
your two implementations extend a common abstract class or implement a
common interface. Then, you can make the determination of which one to
use once and hold onto that object, calling it by the common interface
as needed.

Otherwise, the notion of "if I don't load the class, there will be no
harm in it referencing newer API capabilities" is sound.

Mark Murphy (a Commons Guy)  | 

_The Busy Coder's Guide to Android Development_ Version 2.8