On Mon, Jan 7, 2013 at 4:31 PM, dashman <[email protected]> wrote:
> i'm trying to maintain compatibility with v1.6.
>
> what'll happen when this code is run on v1.6?

That depends a bit on what you have inside the braces.

Let's say that your code is like this:

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB {
    getActionBar().setHomeButtonEnabled(true);
}

On Android 2.0+, this code will execute successfully. On Android 1.6,
your app will crash with a VerifyError as soon as it tries to load
this class, because the 1.x edition of Dalvik will have a conniption
when it cannot resolve getActionBar() or setHomeButtonEnabled() as
possible methods.

If, on the other hand, your code is like this:

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB {
    HoneycombHelper.setHomeButtonEnabled(this);
}

where you have a HoneycombHelper top-level class:

class HoneycombHelper {
    static void setHomeButtonEnabled(Activity a) {
         a.getActionBar().setHomeButtonEnabled(true);
    }
}

This code will work successfully on Android 1.6+.

The key for Android 1.x support is to isolate any references to
new-API classes and methods into some class that will only ever get
loaded on a supported API level.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 4.5 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to