Al.*_*Al. 30 android backwards-compatibility android-3.0-honeycomb
所以我们已经看到了预览sdk以及像ActionBar和Fragments这样的新东西.制作大量的方法调用将不可避免地使用这些,所以有什么策略可以维护1个版本的应用程序,这将让我使用所有时髦的新东西,但也可以在2.3或更低版本的设备上工作?我的应用目标目标是1.5 - 2.3.
Ret*_*ier 27
现在,相同的片段API可用作静态库,以便与旧版本的Android一起使用; 它兼容回到Android 1.6.
您可以使用一些技巧来查看各种新API是否适用于您的应用.一般来说,您可能想要创建两个可选的活动集,一个使用花哨的新API(ActionBar,Animators等) - 另一个不使用.
以下代码显示了如何使用反射和异常捕获来确定Fragment API的可用性,以及如何确认其他Honeycomb API是否可用的版本检查.
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();
}
Run Code Online (Sandbox Code Playgroud)
一般来说,您可以使用相同的布局定义.在片段可用的地方,您将在不同的片段中为每个布局充气,在这些片段中,您可能不希望使用<include>
标签将其中的几个嵌入到更复杂的活动布局中.
有关如何编写代码以支持Honeycomb向后兼容性的更详细的工作,请访问:http://blog.radioactiveyak.com/2011/02/strategies-for-honeycomb-and-backwards.html
归档时间: |
|
查看次数: |
7468 次 |
最近记录: |