Reputation: 75
I have an Android application with 2 activities (actually more, but it doesnt matter here).
The 1st one has fixed orientation (landsape) and the 2nd one has default (undefined) orientation. The 1st activity acts as a splash screen then starts 2nd activity automatically.
The problem is 2nd activity inherits landscape orientation from the 1st one, i.e. if device orientation is vertical when 2nd activity appears it has landscape orientation then immediately rotates to vertical one.
If I remove the 1st activity so that the 2nd one appears during start it doesnt happen.
Note I can neither set vertical orientation for the 1st activity nor set undefined orientation and draw accordingly for some reason.
Please help.
<activity android:name="SplashActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:configChanges="screenSize"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="GameActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize"
android:screenOrientation="fullSensor">
</activity>
I also tried using 'undefined' or not to set any orientation at all for GameActivity.
Upvotes: 2
Views: 654
Reputation: 348
I hope I got it right. So you want, that the second Activity
doesn't get the rotation of the first one.
Use the following inside the onCreate()
method in the second Activity
:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
If it still doesn't help, then it's just Android's behaviour. If it helped, it's good.
After the Intent
in the first Activity
, which should look like this:
Intent intent = new Intent(SplashActivity.this, GameActivity.class);
startActivity(spcthxopen);
You just put
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
under that Intent
. I just tried it and it perfectly workarounds Android's default behaviour.
Upvotes: 1