Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: set activity orientation BEFORE onCreate, but not in manifest (HDMI plugged in issue)

I can perfectly manage orientation change programatically, by using setRequestedOrientation in onCreate.

Everything works really fine, until I plug a HDMI cable. After this, the tablet "wants" to be in landscape mode. So when I open an activity, it shows first in "landscape" and then right after it shows in "portrait", (because I'm calling setRequestedOrientation(variable_with_orientation_desired_by_the_user) where variable=ActivityInfo.SCREEN_ORIENTATION_PORTRAIT in onCreate As you can "see", my app keeps rotating on every activity the user opens;

If I set the orientantion for activity in the manifest, this problem is partially gone, since the orientation in manifest is the same that the user has picked up. If they are different, the same behavior starts again.

I tried this, but with no success:

@Override
public void onCreate(final Bundle saved)
{
    setRequestedOrientation(ScreenOrientation);
    super.onCreate(icicle);
}

So, is there any way to tell to android what orientantion it must create my activity, before it does create it? (But it cannot be in manifest)

like image 670
Christian Avatar asked Dec 01 '22 22:12

Christian


1 Answers

I solved it by setting screenOrientation to "behind" in manifest file:

        android:screenOrientation="behind"
like image 91
Christian Avatar answered Dec 10 '22 11:12

Christian