1.Setting the minSdkVersion —— 设置minSdkVersion值
If the use of a new API is integral to the application — perhaps you need to record video using an API introduced in Android 1.5 (API Level 3) — you should add a <android:minSdkVersion> to the application's manifest, to ensure your app won't be installed on older devices.
2.Using reflection —— 使用反射
3.Using a wrapper class —— 使用包装器
The idea is to create a class that wraps all of the new APIs exposed by a new or existing class. Each method in the wrapper class just calls through to the corresponding real method and returns the same result.
4.Testing is key —— 完备的测试是最关键的
You must test your application on every version of the Android framework that is expected to support it. By definition, the behavior of your application will be different on each. Remember the mantra: if you haven't tried it, it doesn't work.
You can test for backward compatibility by running your application in an emulator that uses an older version of the platform. The Android SDK allows you to do this easily by creating "Android Virtual Devices" with different API levels. Once you create the AVDs, you can test your application with old and new versions of the system, perhaps running them side-by-side to see the differences. More information about emulator AVDs can be found in Creating and Managing Virtual Devices and from emulator -help-virtual-device.
详情请见:http://developer.android.com/resources/articles/backward-compatibility.html
考虑Android向后兼容的几条黄金法则
最新推荐文章于 2024-11-08 23:02:35 发布