Android deprecate warning shows even though I specify api level

android, deprecated

Solution

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();
}

Problem

I am coding to api level 11. So to get the width of the display I have the following function ``` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { Point size = new Point(); display.getSize(size); width = size.x; } else { width = display.getWidth(); } ``` I do all this so I would not get the deprecate warning. But I still get the warning for `getWidth`. Why does the warning not go away? I also get an error for `getSize` saying call requires api level 13 but 11 is detected.

Original source