Android.annotation.SuppressLint

Source: Internet
Author: User

@SuppressLint ("Newapi") in Android code, we sometimes use the android:minsdkversion that we set in Androidmanifest
Version of the method, the compiler prompts for a warning when the workaround is to add @suppresslint ("Newapi") or @targetapi () to the method.
What's the difference between them, very simple,
@SuppressLint ("Newapi") block all new APIs in order to use the method reported by Android Lint error
@TargetApi () block only a new API to use the lint error of a method reported Android
For example, a method that uses the Api9 new method, and the android:minsdkversion=8 of the project settings,
At this point, add @suppresslint ("Newapi") and @targetapi (Build.version_codes) on the method. Gingerbread) All can, the above is the general situation.
And when you refer to a method in this method that api11 only joins, @TargetApi (Build.version_codes. Gingerbread) The method of annotating the error again,
and @suppresslint ("Newapi") will not error, this is the difference.
Of course, regardless of which annotation you use, the role is only to block Android lint errors, so in the method also to determine the version to do different operations, such as:
if (Build.VERSION.SDK_INT >= build.version_codes. Gingerbread) {             //          else {//  Pre gingerbread             //  }  

Android.annotation.SuppressLint

Related Article

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.