Here's my class that accesses 3.0 related functionality.  This is for
the invalidateOptionsMenu API which is now needed on 3.0 to update the
Action Bar properly:

public class SDKLevel11Bridge
{
    private static final SDKLevel11Interface intf;


    private interface SDKLevel11Interface
    {
        void invalidateOptionsMenu(Activity activity);
    }


    private static class SDKLevel11Interface4 implements
SDKLevel11Interface
    {
        SDKLevel11Interface4()
        {
            // Default constructor
        }


        @Override
        public void invalidateOptionsMenu(Activity activity)
        {
            // Nothing
        }
    }


    private static class SDKLevel11Interface11 implements
SDKLevel11Interface
    {
        SDKLevel11Interface11()
        {
            // Default constructor
        }


        @Override
        public void invalidateOptionsMenu(Activity activity)
        {
            activity.invalidateOptionsMenu();
        }
    }


    // Can't instantiate this class
    private SDKLevel11Bridge()
    {
        // Nothing to do
    }


    static
    {
        if (SDKLevelUtil.isAtLeastLevel11())
            intf = new SDKLevel11Interface11();
        else
            intf = new SDKLevel11Interface4();
    }


    public static void invalidateOptionsMenu(Activity activity)
    {
        intf.invalidateOptionsMenu(activity);
    }
}


And the when I need to call the 3.0 API, I just do a:

SDKLevel11Bridge.invalidateOptionsMenu(this);   // "this" is the
current Activity


On Mar 25, 6:24 am, Brion Emde <[email protected]> wrote:
> Hi All,
>
> We're trying to use ActionBars on Honeycomb and stay backward
> compatible with earlier code. Everything seemed to be fine when we
> just used the default behaviors, like the upgrade of options menus to
> show in the action bar as Actions.
>
> But then the requirements got broader and they wanted us to start
> styling the action bar, setting its background, adding the "go to
> home" indicator to the icon and other things and we lost our backwards
> compatibility.
>
> I've been trying to figure it out and saw this paragaph in the "using
> action bars" document:
>
> ---
>
> In this example, the application requires a minimum version of API
> Level 4 (Android 1.6), but it also targets API Level 11 (Android 3.0).
> This way, when the application is installed on a device running
> Android 3.0 or greater, the system applies the holographic theme to
> each activity, and thus, each activity includes the Action Bar.
>
> However, if you want to use Action Bar APIs, such as to add tabs or
> modify Action Bar styles, you need to set the android:minSdkVersion to
> "11", so you can access the ActionBar class.
>
> ---
>
> This seems to say that if we want to talk to the ActionBar directly,
> i.e. use the Action Bar API, that we have to set our minSdkVerion="11"
> in the manifest.
>
> I'm having an argument with my boss, who thinks that since it "works"
> on Honeycomb, that the above excerpt does not apply to us. But I point
> out that when I comment out the code that tries to talk to the action
> bar directly, then I don't get Verify Errors on pre-Honeycomb devices.
> Everything used to work fine before we started trying to talk to the
> Action Bar directly.
>
> So, does that section, specifically the second paragraph that starts
> with "However", which seems to modify the paragraph before it, really
> apply? If so, why can we talk to the ActionBar on Honeycomb devices,
> despite our minSdkVersion="8".
>
> Our access to the action bar is wrapped in a wrapper class, as
> described in the "backwards compatilibility" article.
>
> Thanks!!

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