简体   繁体   English

Android向后兼容技术

[英]Android backward compatibility techniques

I am now advanced in developing my 15-activities android app which is based on the latest API (15 ICS). 我现在正在开发基于最新API(15 ICS)的15活动Android应用程序。 Now I discovered that main functionalists of the app is NOT backward compatible even with the android v4 support such as: 现在我发现应用程序的主要功能主义者即使对于android v4支持也不向后兼容,例如:

1-fragmentTransaction animation 2-the ability to putStringSet in sharedPref 3-having mapActivity using fragments 1-fragmentTransaction动画2-使用片段在具有mapActivity的sharedPref 3中putStringSet的能力

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. 我考虑为EACH类的旧操作系统制作第二个版本,它具有不兼容问题(大约10个),所以如果我检测到运行应用程序的设备是旧的,我会使用它们。 However, I am sure this is a stupid way and there is a better way of doing this. 但是,我确信这是一种愚蠢的方式,并且有更好的方法。

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 ) 使代码与API 7兼容的最佳方法是什么,而不会让功能提供更高的API(至少用于较新的设备)

You can check the API level in android at runtime and enable the required features as per the API level. 您可以在运行时检查android中的API级别,并根据API级别启用所需的功能。

Something like below. 像下面的东西。

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
}

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) 此外,您可以将版本限定符添加到资源文件夹,例如drawable-v15(如果设备API级别为15,则将提取drawables)

Check this LINK for more information on how to specify the required qualifiers for the resources 有关如何为资源指定所需限定符的详细信息,请查看此LINK

with this the latest functionality available will be enabled when launched on latest firmware devices and backward compatibility is enabled otherwise. 使用此功能时,将在最新固件设备上启用时启用最新功能,否则启用向后兼容性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM