문제

Sometimes I case out code for certain versions of Android that may run my application. Eclipse with the latest Android tools still notices that my Manifest document allows lower versions of Android and therefore decides my code has errors in it.

A solution to this is to add a @Suppress tag above the method so it doesn't report the error, or another suggestion is to add a @TargetApi tag above the function

I dont understand the differences, or the consequences

도움이 되었습니까?

해결책

@TargetApi(NN) says "Hey, Android! Yes, I know I am using something newer than what is allowed for in my android:minSdkVersion. That's OK, though, 'cause I am sure that I am using Build (or something) such that the newer code only runs on newer devices. Please pretend that my minSdkVersion is NN for the purposes of this (class|method)".

@SuppressLint, to address the same error, says "Hey, Android! Yes, I know I am using something newer than what is allowed for in my android:minSdkVersion. Quit complaining.".

Hence, given a choice of @TargetApi(NN) or @SuppressLint, go with @TargetApi(NN). There, if you start using something newer than NN -- and therefore your existing version-checking logic may be insufficient -- you will get yelled at again.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top