开发者

What is the better way of creating Windowmanager instance android

I found the following two ways of creating WindowManager instance

WindowManager w = activity.getWindowManager();

and

WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);

but in Motorola Milestone if I use the first approach of creating WindowManager then I am not getting accurate width of my device

to get width i have used windowManager.getDefaultDisplay().getWidth();

But If I use the second approach then I am getting accurate width of device.

I have tested in motorla milestone

  • What is the difference between these two types of WindowManager.
  • Why i am getting different results.
  • What is t开发者_运维百科he better way of creating WindowManager instance?


I believe the second way of getting windowmanager instance is better since it is using the system's information rather than the information from the current activity. Also, as you can see in here the second way of getting a windowmanager instance is recommended by the android developers website. The reason that the results of the two may be different is that since motorola has to configure the android os to be compatible to their phones, this method may have been changed. The second option is probably more legitimate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜