策略蜂窝和放大器;向后兼容性放大器、蜂窝、兼容性、策略

2023-09-14 00:06:33 作者:名字还没想好

因此​​,我们已经看到了preVIEW SDK和整齐的新的东西,如动作条和片段。制作了大量的方法调用将是不可避免的,以利用这些,有什么策略有维持1版本的应用程序,这将让我用所有的时髦新的东西,而且在运行2.3或以下的设备正常工作?我的应用程序的目标1.5 - 2.3的时刻。

So we've seen the preview sdk and the neat new stuff like ActionBar and Fragments. Making a lot of method calls will be unavoidable to make use of these, so what strategies are there for maintaining 1 version of the app, which will let me use all the snazzy new stuff but also work on devices running 2.3 or below? My app targets 1.5 - 2.3 at the moment.

推荐答案

该片段的API现在可以作为的静态库为了与旧版本的Andr​​oid的使用;它是兼容的右后卫到Android 1.6。

The same fragment APIs are now available as a static library for use with older versions of Android; it's compatible right back to Android 1.6.

有一些技巧,你可以用它来看看各种新的API提供给您的应用程序。一般来说,你可能会想创建两个备选集活动,一个使用花哨的新API(动作条,动画等) - 而另一组不

There are a few tricks you can use to see if the various new APIs are available to your app. Generally speaking, you'll probably want to create two alternative sets of Activities, one that uses the fancy new APIs (ActionBar, Animators, etc.) -- and another set that don't.

下面code显示了如何使用反射和异常捕获,以确定片段的API的可用性和版本检查,以确认是否其他蜂窝的API是可用的。

The following code shows how you can use reflection and exception catching to determine the availability of the Fragment APIs, and version checking to confirm if the other Honeycomb APIs are available.

  private static boolean shinyNewAPIsSupported = android.os.Build.VERSION.SDK_INT > 10;

  private static boolean fragmentsSupported = false;

  private static void checkFragmentsSupported() throws NoClassDefFoundError {
    fragmentsSupported = android.app.Fragment.class != null;
  }

  static {
    try {
      checkFragmentsSupported();
    } catch (NoClassDefFoundError e) {
      fragmentsSupported = false;
    }
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent startActivityIntent = null;
    if (!shinyNewAPIsSupported)
      startActivityIntent = new Intent(this, MainNonActionBarActivity.class);
    else
      startActivityIntent = new Intent(this, MainActionActivity.class);

    startActivity(startActivityIntent);
    finish();
  }

一般来说可以使用相同的布局定义。当片段可你会在不同的片段,如果他们不是,你可能会想使用夸大每个布局<包括> 标签嵌入其中几个为更复杂的活动布局。

Generally speaking you can use the same layout definitions. Where Fragments are available you'll inflate each layout within a different Fragment, where they aren't you'll probably want to use <include> tags to embed several of them into a more complex Activity layout.

通过怎么写code更详细的工作,支持蜂窝向后兼容性可以在这里找到:http://blog.radioactiveyak.com/2011/02/strategies-for-honeycomb-and-backwards.html

A more detailed work through of how to write the code to support backwards compatibility on Honeycomb can be found here: http://blog.radioactiveyak.com/2011/02/strategies-for-honeycomb-and-backwards.html