Android: Temporarily disable orientation changes in an Activity

As explained by Chris in his self-answer, calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); and then setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); really works like charm… on real devices ! Don’t think that it’s broken when testing on the emulator, the ctrl+F11 shortcut ALWAYS change the screen orientation, without emulating sensors moves. EDIT: this was not the best possible answer. As explained in the comments, … Read more

Force an Android activity to always use landscape mode

Looking at the AndroidManifest.xml (link), on line 9: <activity android:screenOrientation=”landscape” android:configChanges=”orientation|keyboardHidden” android:name=”VncCanvasActivity”> This line specifies the screenOrientation as landscape, but author goes further in overriding any screen orientation changes with configChanges=”orientation|keyboardHidden”. This points to a overridden function in VncCanvasActivity.java. If you look at VncCanvasActivity, on line 109 is the overrided function: @Override public void onConfigurationChanged(Configuration … Read more

Background task, progress dialog, orientation change – is there any 100% working solution?

Step #1: Make your AsyncTask a static nested class, or an entirely separate class, just not an inner (non-static nested) class. Step #2: Have the AsyncTask hold onto the Activity via a data member, set via the constructor and a setter. Step #3: When creating the AsyncTask, supply the current Activity to the constructor. Step … Read more

How do I disable orientation change on Android?

Update April 2013: Don’t do this. It wasn’t a good idea in 2009 when I first answered the question and it really isn’t a good idea now. See this answer by hackbod for reasons: Avoid reloading activity with asynctask on orientation change in android Add android:configChanges=”keyboardHidden|orientation” to your AndroidManifest.xml. This tells the system what configuration … Read more

How can I disable landscape mode in Android?

Add android:screenOrientation=”portrait” to the activity in the AndroidManifest.xml. For example: <activity android:name=”.SomeActivity” android:label=”@string/app_name” android:screenOrientation=”portrait” /> Since this has become a super-popular answer, I feel very guilty as forcing portrait is rarely the right solution to the problems it’s frequently applied to. The major caveats with forced portrait: This does not absolve you of having to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)