Searching on google i found various way get the screen size, here's what i got.
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
Log.i(TAG, "first way width = "+size.x);
Log.i(TAG, "first way height = "+size.y);
int width = getWindowManager().getDefaultDisplay().getWidth();
int height = getWindowManager().getDefaultDisplay().getHeight();
Log.i(TAG, "second way width = "+width);
Log.i(TAG, "second way height = "+height);
int height2 = Resources.getSystem().getDisplayMetrics().heightPixels;
int width2 = Resources.getSystem().getDisplayMetrics().widthPixels;
Log.i(TAG, "third way width = "+width2);
Log.i(TAG, "third way height = "+height2);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height3 = displaymetrics.heightPixels;
int width3 = displaymetrics.widthPixels;
Log.i(TAG, "fourth way width = "+width3);
Log.i(TAG, "fourth way height = "+height3);
On logging all are giving the same result. I was wondering if there any difference between all these methods or any specific use cases? Thanks in advance.