Before,I saw this snippet to find Height of statusbar?(and also Tiltebar)
here:
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop=
window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;
Yesterday,I tried to use this snippet in an AsyncTask
class.So I send instance of my Activity to AsyncTask
class,in onCreate
of Activity:
LongOperation loper = new LongOperation(this, vg, vArray, hintsArray,x_positionArray, y_positionArray);//Here `this` refers to current Activity
loper.execute("YES");
In doInBackground of AsynkTask class I only did:
Thread.sleep(3000);
And in onPostExecute
method I copy above code to calculate height of statusbar and titlebar.But App crashes,without any useful log in logcat.Then I comment some lines like this:
Rect rectgle = new Rect();
Window window = activity.getWindow();
// window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
// int StatusBarHeight= rectgle.top;
contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT)
.getTop();
// int TitleBarHeight= contentViewTop - StatusBarHeight;
and App works fine.So it seems that
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
causes App crashing,But I do not know why?Did I do some thing incorrect?