Use the high version function @suppresslint ("Newapi") or @TargetApi in the lower version of the SDK?

Source: Internet
Author: User

@SuppressLint and @TargetApi achieve the same effect, relative to Suppresslint, TARGETAPI will be based on the API used in the function, strictly match the SDK version, give a compilation error, but Suppresslint The SDK version is ignored.

For example:

[Java]View Plaincopy
  1. @TargetApi (build.version_codes. FROYO)
  2. public Static File Getexternalcachedir (context context) {
  3. File dir;
  4. if (! Versionutils.hasdonut ()) {
  5. if (! Versionutils.hasfroyo ()) {
  6. dir = new File (Environment.getexternalstoragedirectory (). GetPath ()
  7. + "/android/data/" + context.getpackagename () + "/cache/");
  8. if (!dir.exists () &&!dir.mkdirs ())
  9. DIR = null;
  10. } Else {
  11. dir = Context.getexternalcachedir ();
  12. }
  13. return dir;
  14. }

If you change Versionutils.hasfroyo () to Versionutils.hasdonut (), the compilation error will be reported, and if it is @suppresslint ("Newapi") the error will not be indicated. More rigorous point of view, more recommended TARGETAPI

Original address: http://blog.csdn.net/hero_yin/article/details/23081129

(RPM) Use the High version function @suppresslint ("Newapi") or @TargetApi in the lower version of the SDK?

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.