Activity flashes up in portrait before switching to landscape

故事扮演 提交于 2019-12-08 09:34:41

问题


I am creating an android game where every activity is set to be in landscape in the xml manifest file.

However, sometimes when going to a new activity it flashes up in portrait for a second before correcting to landscape.

Does anyone have any generic reason why this might be?

It happens when exiting the level completion screen too early which uses a ScheduledFuture

Thanks Andy

EDIT (Manifest):

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appsolutely.sheepherder"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.appsolutely.sheepherder.Main"
        android:label="@string/app_name"
        android:screenOrientation="landscape" >
    </activity>
    <activity
        android:name="com.appsolutely.sheepherder.Game"
        android:label="@string/title_activity_game"
        android:screenOrientation="landscape" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.appsolutely.sheepherder.LevelSelect" />
    </activity>
    <activity
        android:name="com.appsolutely.sheepherder.LevelSelect"
        android:label="@string/title_activity_level_select"
        android:screenOrientation="landscape" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.appsolutely.sheepherder.Main" />
    </activity>
    <activity
        android:name="com.appsolutely.sheepherder.Splash"
        android:label="@string/app_name"
        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="com.appsolutely.sheepherder.Plague"
        android:label="@string/title_activity_plague"
        android:screenOrientation="landscape"  >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.appsolutely.sheepherder.Main" />
    </activity>
</application>


回答1:


Try to add screenOrientation to your manifest:

<activity android:screenOrientation="sensorLandscape" ...>

I suggest to use sensorLandscape so the user can choose if the divice is rotated to the right or the left.



来源:https://stackoverflow.com/questions/14691443/activity-flashes-up-in-portrait-before-switching-to-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!