Android backward compatibility techniques

和自甴很熟 提交于 2019-12-07 17:25:11

问题


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 animation 2-the ability to putStringSet in sharedPref 3-having mapActivity using fragments

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.

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 )


回答1:


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

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)

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.



来源:https://stackoverflow.com/questions/10880830/android-backward-compatibility-techniques

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!