I'm using this code, to get screen size
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.some_layout);
//more stuff
setTextSize();
}
private void setTextSize() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
//more code
sometextview.setTextSize(TypedValue.COMPLEX_UNIT_PX, width/10); //example only
}
As it turns out, in rare cases this doesn't work. I'm setting some text size, and sometimes it doesn't resize text at all. I think it only happens whenever I haven't open application in a while, so it's very hard to debug it. Only idea I have is, that this is asking for screen size before application even knows it (it's the first activity). How can I solve this? This is the only method for getting screen resolution that I know that supports all APIs.