The IDE isn't quite intelligent enough to realise what you are trying to do here, hence why you are still getting warnings.
If you were hellbent on getting rid of them, you could define two methods: one which executes the code in the Honeycomb route, and has the annotation @TargetApi(13)
and the second which executes the code in the other route with the annotation @SuppressWarnings("deprecation")
. Personally, I wouldn't worry.
Example:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
width = getWidthHoneycombMR2();
}
else {
width = getWidthLegacy(display);
}
...
@TargetApi(13)
public int getWidthHoneycombMR2() {
Point size = new Point();
display.getSize(size);
return size.x;
}
@SuppressWarnings("deprecation")
public int getWidthLegacy(Display display) {
return display.getWidth();
}