Android的向后兼容技术 [英] Android backward compatibility techniques

查看:160
本文介绍了Android的向后兼容技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在开发我的15活动Android应用程序是基于最新的API(15 ICS)先进。现在我发现,应用程序的主要功能主义是不是向后兼容的,甚至与Android V4支持,如:

I am now advanced in developing my 15-activities android app which is based on the latest API (15 ICS). Now I discovered that main functionalists of the app is NOT backward compatible even with the android v4 support such as:

1-fragmentTransaction动画
2,能力putStringSet共享preF
3,具有使用mapActivity片段

1-fragmentTransaction animation 2-the ability to putStringSet in sharedPref 3-having mapActivity using fragments

我想过做第二个版本有不兼容问题(这是10左右),每个类的旧操作系统的,所以我使用他们,如果我检测到运行该应用的设备是旧的。不过,我相信这是一个愚蠢的方式并没有这样做的更好的方法。

I thought about making a second version for the older OS's of EACH class that has incompatibility issues (which are around 10) so I use them if I detect that the device running the app is old. However, I am sure this is a stupid way and there is a better way of doing this.

什么是使你的code。与API 7兼容,最多不留所提供的更高的API(至少用于新设备)功能的最佳方式。

What is the best way to make your code compatible with API 7 and up without leaving the the features provided higher APIs ( at least to be used for the newer devices )

推荐答案

您可以在运行时检查的Andr​​oid API级别和启用所需的功能,按API级别。

You can check the API level in android at runtime and enable the required features as per the API level.

类似下面。

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
// Do something for ICS and above versions
} else{
// do something for phones running an SDK before ICS
}

此外,你可以版本限定符添加到资源文件夹,例如绘制-V15(将皮卡可绘制如果设备API级别为15)

Additionally you can add the version qualifier to the resource folder such as drawable-v15 (will pickup drawables if the device API level is 15)

勾选此链接关于如何指定更多信息该资源所需的限定符

Check this LINK for more information on how to specify the required qualifiers for the resources

本可在最新的固件设备和向后兼容性启动时将启用最新的功能,否则启用。

with this the latest functionality available will be enabled when launched on latest firmware devices and backward compatibility is enabled otherwise.

这篇关于Android的向后兼容技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆