I want my app to run in the portrait view so I made the following changes in the android manifest file.
android:screenOrientation="portrait"
It stays in the portrait view for a second and then it closes.. I had assumed this is the only change i had to make..but i also added this but it isnt working
android:configChanges="orientation"
Am i missing something?
<activity android:name=".Menu" android:label="COMEDY TRIVIA"
android:screenOrientation="portrait" android:configChanges="orientation"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="nik.trivia.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Try this adding android:configChanges to your AndroidManifest file in the activity tag
<activity android:name=".Fourth" android:label="Fourth" android:configChanges="orientation|keyboardHidden"></activity>
Hope this works for you.
Related
I'm developing a game that runs in a wrapped webview for Android devices. Everything is working as expected--in this case, I have locked my view to landscape orientation, and prevented the device from restarting the activity if the phone is rotated.
However, if I put my device to sleep and then unlock it, I see my application in portrait mode for a moment, until my device re-orients to landscape. This behavior makes sense, since a phone is naturally used in portrait orientation, but I don't want my activity to switch from landscape.
If I start any other game, by which I mean those presumable written in native code, that is locked into landscape mode, and then lock and unlock my phone, the game doesn't do the same quickly-switch-from-portrait-to-landscape dance.
What am I missing?
In MainActivity I have
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
in several places, including onConfigurationChanged, onWindowFocusChanged, onPause, and onResume.
Here is how my activity is defined in my AndroidManifest
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:screenOrientation="sensorLandscape"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Thanks for any help/advise!
-J.L.
You forgot to remove sensor from the screenOrientation tag. Try this:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
the app still shows as the incorrect orientation for a split second when the phone is unlocked.
Did you move setContentView(R.layout.main) to the onResume, AFTER where you put your orientation code? I would try setting the orientation, then the setContentView()
I need to disable splash screen auto rotate.
Need to show splash screen in portrait mode only. But app must rotate with auto rotate. How to do it in android studio ?
Add in Manifest file-->
<application
.........
>
<activity
android:name=".SplashScreenActivity"
......
android:screenOrientation="portrait"
/>
</application>
or for horizontal mode
<activity
...
...
android:screenOrientation="landscape">
In Your AndroidMainfest.xml put the screen orientation to your splash
<activity
android:name=".SplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In the manifest, set this for your splash screen activity:
<activity android:name=".YourActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"/>
In manifest you can set the specific activity to be in portrait mode using
android:screenOrientation="portrait"
Just add below line in your manifest file, in splash activity tag
android:screenOrientation="portrait"
Something like below
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait" >
Add to your splash activity declaration in the manifest this lines:
<activity
android:name="SplashActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
Find relevant discussion here.
You Can do it by couple of ways
One
Inside the onCreate method of your activity
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Two
In manifest file
<activity
android:name=".NameOfYourSplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Hope it helps
Add following code to your splash screen activity declaration in Manifest
<activity android:name=".YourActivityName"
android:label="#string/app_name"
android:configChanges = "orientation"
android:screenOrientation = "portrait">
or else add
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
to YourActivity.onCreate()
you can find a sample demo file here in github
try this in manifiest
<activity
android:name=".SplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"/>
My Titanium Appceleartor(version 3.1.3) app has both portrait & landscape orientations. But in Android device, even when i enabled the "screen rotation" mode, my app renders in both orientation modes. How to prevent the App from rendering in landscape mode when device is "screenLocked"?
My TiApp.xml;
<activity android:alwaysRetainTaskState="true"
android:configChanges="keyboardHidden|Orientation"
android:label="SampleApp" android:name=".SampleAppActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
you need to set protrait orientation to each activity tag
<activity android:alwaysRetainTaskState="true"
android:configChanges="keyboardHidden|Orientation"
android:screenOrientation="portrait"
android:label="SampleApp" android:name=".SampleAppActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
so i would suggest to use custom android manifest.
Copy your AndroidManifest.xml file from build/android folder and put it into the platform/android/ folder of your application. If folders are not present then create them. Now put a android:screenOrientation="portrait" in each activity tag like this:
<activity android:name="YourActivityName"
android:label="YourActName" android:theme="#style/Theme.Titanium"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Hi all thanks for the help. I have added these things already in my tiapp.xml. But still problem exists. I figured out that i have set OrientationMode property to all windows in my app, which should not be set because Android takes all 4 orientations by default. We don't need to specify it in code. So i removed this property & now everything works fine..
I am facing an issue that ,When ever I start the app and press home button ,then again I click the apps icon a new instance of that app is created . How to solve this issue ?
My Manifest file as follows ,
<activity
android:name="com.example.mytast.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:alwaysRetainTaskState="True"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Add:
<activity
android:name="com.example.mytast.MainActivity"
android:launchMode="singleTask"
...
>
</activity>
and remove:
android:alwaysRetainTaskState="true"
from the directive.
I want to keep landscape mode always.
I Lock screen to portrait mode on Nexus7, I set android:screenOrientation="sensorLandscape" and android:configChanges="orientation|keyboardHidden"in AndroidManifest.xml, when I go to other activity and back to this activity, then the screen will rotate portrait and rotate to landscape again (Didn't call onCreate method again), but I don't want to rotate the screen in any situations, how to fix it?
I think this is the answere you're looking for:
stackoverflow.com/a/2730894/2249774
For All your Activities in the manifest set
android:screenOrientation="sensorLandscape" android:configChanges="orientation|keyboardHidden"
Example :-
<activity android:name="com.example.test.testActivity" android:label="#string/app_name" android:screenOrientation="sensorLandscape" android:configChanges="orientation|keyboardHidden"">
<intent-filter>
<action android:name="com.example.test.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Repeat this for all activities used in the manifest..
Try editing your AndroidManifest.xml to look like this
<activity
android:name=".YOURACTIVITYNAME"
android:screenOrientation="landscape" />
In your AndroidManifest file, try typing in the following code:
android:configChanges="keyboard|orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
example:
<activity
android:name="com.gaspar.slinfilipino.Quiz"
android:label="#string/title_activity_quiz"
android:configChanges="keyboard|orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
android:parentActivityName="com.gaspar.slinfilipino.SignLanguageMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.gaspar.slinfilipino.SignLanguageMenu" />
</activity>