Cleaning up deprecation methods


YMMV, but I got teh red squiggly when using getSize() [sans parameter].
The “something like this” code at the end of the chapter for using getSize() as opposed to getWidth() && getHeight() should probably be amended to reflect display.getSize(Point).



Point size = new Point; display.getSize(size);

It’s probably also worth tossing a @TargetAPI up top just to further shut the IDE up.


Are you using IntelliJ? This might be an IntelliJ vs. Eclipse issue - in the text, we go with @SuppressWarnings rather than @TargetApi to silence this warning.

As far as using display.getSize(Point) vs. getWidth() and getHeight(), this is one of those mildly irritating Android deprecation issues. We try to keep the amount of typing it takes to get through the book to a minimum. Using Display.getSize(Point) would require an if statement to switch between the deprecated call and the new call, which would bloat two lines into six lines. It’s a little thing, but a thing we think about.

In truth, getWidth() and getHeight() will probably be around for a while now, so we elected to go ahead and call them anyway. In your own code, it may be marginally more robust to go with the longer code.


I do use IntelliJ, and I can/do appreciate why the main code in the chapter was presented the way it was. (This post was specifically about the “for the more curious” section).

I don’t believe the error I’m referring to is an IntelliJ error. I believe the error is a typographical error regarding display.getSize() v display.getSize(Point), specifically that the former is not a valid (at least not a documented) method in the Android API (maybe there’s a different library for display?). Which might make it an Eclipse error/quirk that it would accept such a method call*.

I guess it’s not that big of a deal. I suppose if one is ‘more curious’ then by definition one would dig into this sort of situation and root out the real deal… maybe even learn a thing or two. But perhaps that’s the point? Thank you for taking the time to respond to me.

*I’ve never used Eclipse (I have some mental blockade in place that prevents me from installing it), but if it does allow this sort of disembodiment of method calls I think I will only further shore up the foundations of my blockade.


Ahh, I see what you’re pointing out now - yes, getSize() does not exist. My apologies, I misinterpreted what you were saying. I’ll add it to the errata.

I wouldn’t bother using both Eclipse and IntelliJ, either.