@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
- @TargetApi (build.version_codes. FROYO)
- public Static File Getexternalcachedir (context context) {
- File dir;
- if (! Versionutils.hasdonut ()) {
- if (! Versionutils.hasfroyo ()) {
- dir = new File (Environment.getexternalstoragedirectory (). GetPath ()
- + "/android/data/" + context.getpackagename () + "/cache/");
- if (!dir.exists () &&!dir.mkdirs ())
- DIR = null;
- } Else {
- dir = Context.getexternalcachedir ();
- }
- return dir;
- }
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?