Only want to block orientation until all the data is loaded in my view. So I thought about the following code but it doesn't work.
private class task extends AsyncTask<String, Void, String> {
protected String doInBackground(String... params) {
...
}
protected void onPostExecute(String result) {
...
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
protected void onPreExecute() {
...
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}
}
When I run these two lines of SENSOR and NOSENSOR my screen turns horizontal automatically, without understanding why. That may be happening?
EDIT: I put the following lines to check the current orientation with the following result:
protected void onPreExecute() {
if (getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE) {
Log.e("TAG","LANDSCAPE");
}else{
Log.e("TAG","PORTRAIT");
}
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}
Result of Logcat:
LANDSCAPE
But if I remove the two lines (SetRequestedOrientation) do I get this in logcat:
PORTRAIT