Reputation: 6912
Below is my code.
I want to set it disable auto change screen orientation.
And enable auto change screen orientation.
class NewLoad extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog = new ProgressDialog(this);
progDailog.setMessage("test");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(false);
progDailog.show();
//set disable auto change
}
@Override
protected String doInBackground(String... aurl) {
//do something
return null;
}
@Override
protected void onPostExecute(String unused) {
super.onPostExecute(unused);
progDailog.dismiss();
//set enable auto change
}
}
How can I do it?
Upvotes: 3
Views: 1600
Reputation: 136
In runtime:
When you want to block sensor:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
When you want to activate:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
http://developer.android.com/reference/android/app/Activity.html
Upvotes: 1
Reputation: 15701
disable auto change screen orientation.And enable auto change screen orientation.
if you want to do at run time
try :
Upvotes: 2
Reputation: 28093
Make your activity to look something like this in manifest
<activity
android:name=".Hello"
android:label="@string/app_name"
android:screenOrientation="portrait" <-- Screen will be forced to have portrait
android:configChanges="orientation|keyboardHidden|screensize" > <-- No Restart in these cases
ScreenSize attribute seems to be added in 4.0 so don't mentioned it if you are ruuning below 4.0.
Upvotes: 7