2

I'm getting a "The method getHeight() from the type Display is deprecated" error when trying to get the Height and Width of the screen size, code:

public JumpboyView(MyView mv, Context contextPlay) {
    super(contextPlay);
    // TODO Auto-generated constructor stub
    bBoy = BitmapFactory.decodeResource(getResources(), R.drawable.boy);

    Display display = ((WindowManager) contextPlay.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    height = display.getHeight();

and when trying to use getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

I get "The method getWindowManager() is undefined for the type JumpboyView" with 2 fixes available change to getWindowToken() or create method..

Help please?

p.s it used to work on older versions :\

codeoverflow
  • 143
  • 2
  • 12

1 Answers1

2

Try this:

    Display display = ((WindowManager) contextPlay.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    height = size.y
sdabet
  • 18,360
  • 11
  • 89
  • 158
  • display.getSize(size) you mean? seems to work with no erros, but my app doesn't seem to work for other reasons now, since that one is already fixed, I'll see what's next. Thanks! – codeoverflow Jan 18 '13 at 15:33
  • weird...It used to work with older versions, now with only this error and hopefully its fixed right, app "Unfortunately stops working".. – codeoverflow Jan 18 '13 at 15:38