Set screen orientation of application in android - android

Here is my code to set orientation of screen
<activity
android:name="com.srikanth.lullaby.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.SoundRecordingActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.RecorderActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.MediaplayerExample"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.MediaPlayerActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
but it is not working properly ,when i rotate the screen then app changing its direction
How to fix this.

Try this..
Just remove
android:configChanges="orientation"
Or in your java add this line after setContentView(R.layout.yourlayout);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Try to add like this for every activity tag:
<activity
android:name="com.srikanth.lullaby.RecorderActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>

Try this
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
use theme in Application tag
android:theme="#android:style/Theme.Black.NoTitleBar"

android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation|screenSize"
The android:configChanges line prevents onResume(), onPause() from being called when the screen is rotated. Without this line, the rotation will stay as you requested but the calls will still be made.
keyboardHidden and orientation are required for < Android 3.2 (API level 13), and all three options are required 3.2 or above, not just orientation.

Related

Textbox gone hide under keyboard in my webview Android app

This is my androidmanifest.xml activity code:
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen">
<intent-filter >
Use below code in all activity tag in MeniFest file
<activity android:label="#string/app_name"
android:hardwareAccelerated="true"
android:name="com.apnabanaras.ShowWebView"
android:windowSoftInputMode="adjustPan|adjustResize"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscr‌​een"/>
and remove this line
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
test this attribute:
<activity
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:name="com.apnabanaras.ShowWebView"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscr‌​‌​een">

How to disable splash screen auto rotate in android app?

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"/>

android:screenOrientation="portrait" ignored on a Nexus 5x running Marshmallow

I am getting reports that my supposedly portrait app can be rotated to landscape mode on a Nexus 5X running Marshmallow. I don't have one to test on but why is this happening? Here is my activity in the manifest:
<activity
android:name=".app.MainActivity_"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Activity"
android:launchMode="singleTask"
>
</activity>
Try and change your tragetSDKVersion from Marshmallow to Lollipop.
It worked for me.
You must use this for the Activity!
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
and for the whole application you must use this code which will force the orientation not to be landscape
<application
android:debuggable="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">

Activity Not Found Exception (Activities declared and running perfectly before)

I had an app with several activities running perfectly until I added a new activity, which became the launch activity.
Now, the app stars in that activity but when I go to another activity it says Activity Not Found Exception even the activities are declared.
Here is my manifest, as I do not know what I am missing.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.visualizacion.Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".com.example.cuestionario.Page1"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape"></activity>
<activity android:name=".com.example.cuestionario.Page3"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape"></activity>
<activity android:name="com.example.cuestionario.Page2"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape" ></activity>
<activity android:name="com.example.cuestionario.Page4"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape" ></activity>
<activity android:name="com.example.cuestionario.Page5"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape" ></activity>
<activity android:name="com.example.cuestionario.Page6"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape" ></activity>
<activity android:name="com.example.cuestionario.Page7"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape" ></activity>
<activity android:name="com.example.visualizacion.Page1C"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape" ></activity>
<activity android:name="com.example.visualiacion.Page2C"
android:configChanges="orientation"
android:screenOrientation="sensorLandscape" ></activity>
</application>
When I go from Menu (Launcher Activity) to another activity it crashes with that exception.
Thank you
Check package path of your classes declared in Android Manifest and remove .(dot) from full class name. for Page1 and Page 3. i.e
android:name=".com.example.cuestionario.Page1"
and
android:name=".com.example.cuestionario.Page3"

Android app closes when the orientation is changed

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.

Categories

Resources