Android API compatibility on different versions of the system

Source: Internet
Author: User

As the Android version continues to update, the new API is constantly gushing, and sometimes the high-version API is crash in the lower version.

If the minsdkversion setting is too low, the error will be in the build (call requires API level 9);

In order to compile can pass, can add @SuppressLint("NewApi") or@TargeApi(9)注解。

This is only compiled through, the runtime will still be crash.

The right approach

In order to run without error, you need:

  1. Determine the runtime version, this method is not called in the low-version system
  2. In order to ensure the integrity of the function, we need to provide the low-version function

Summary: Using a method higher than minSdkVersion the API level requires:

  1. If @TargeApi($API_LEVEL) the use can be compiled through, then do not use @SuppressLint("NewApi") ;
  2. Run-time judgment API level; This method is only called in an API level system that is high enough to have this method;
  3. Ensure functional integrity and ensure that low API versions provide functionality through other methods.

Easy to ignore the API small details, fortunately, IDE development tools, will automatically remind you of.

Android API compatibility on different versions of the system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.