Launching android app in Landscape mode - android

I want my app to be displayed only in Portrait mode. I
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);) as long as the app is launched in Portrait mode and then change it to landscape when the app is running.
The issue is, if I launch the app in Landscape mode, it displays the Splash Screen for a second and then goes all black and again displays the Splash Screen. this keeps going on forever and never proceeds to the next screen.
any help on resolving this issue is much appreciated.
thanks.

You can it inside the manifest on your activity
<activity android:name=".MainActivity" android:screenOrientation="portrait" />

Recheck your Manifest.xml - who is the launcher activity and who is the default.
also recheck which activity you call from the splash screen. maybe the name has changed for some reason.
If not, try using this answer: Android - switching between landscape and portrait mode makes Intent lose values

I don know what code have you written .. probably if you can share few snippet of code where you are calling splashscreen and after some timeinterval you call another activity ... we could provide you a solution.

Related

Screen still can rotate even if orientation is set to Portrait

I know the tile seems to be very confusing, but yeah, it happened to my application. Ok, here's the story.
Here's the key settings in Manifest:
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
In my Activity.java, I also override onConfigurationChanged(Configuration config), which will print out current orientation.
Here comes the most interesting part. I start a rotatable Application, say Gallery (assume it can rotate), from my application in landscape using Intent. Keep the phone in landscape, and press back key. The newly launched activity, in this case Gallery, will quit, and my application will restart. In theory, my application should display in portrait since I have set the screenOrientation to portrait. However, in reality, my application just stays in portrait for 1 second, and then jumps to landscape, and jumps back to portrait again.
I start a thread to print out requestedOrientation of my application after onRestart is called. And I find out that the output is always "1", which is "portrait". Yet, the output from onConfigurationChanged gives my a current orientation of landscape!
So, I'm totally confused. How can this happen? Can someone give me some advice?
May be you use screen orientation in an activity. But another activity will be rotate. in below example ActivityA's orientation will not change but ActivityB will be rotate. If you write android:screenOrientation="portrait" in app tag and not mention anything in activity. It doesn't work anything. So please mention screenOrientation in activity.
<activity
android:name=".ActivityA"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ActivityB">
</activity>
are you using android:screenOrientation="portrait"
android:configChanges="orientation|screenSize|keyboardHidden"
inside your application or under activity

Can a live wallpaper lock the screen in portrait mode?

Can a live wallpaper lock the screen in portrait mode? And if so, how?
I should mention that I have seen two supposed answers to this question on SO, one appeared inordinately complicated, I didn't understand it all and the answer was not accepted by the original poster. The second answer didn't work for me.
A third answer involving the use of:
android:screenOrientatin = "portrait" or "landscape"
has been suggested, but it is not clear exactly where this should go in the manifest.
EDIT: have tried putting android:screenOrientation="portrait" in many different places in the manifest, and none of them worked.
EDIT: another answer was to rotate your bitmaps and handle a rotation by just drawing everything sideways - but this looks very ugly because, as you rotate you phone, the OS instigates a rotation animation - which means that you get a horrid jumping effect as you turn the phone.
I'm beginning to suspect that the true answer is simply "no".
Did you try setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ?
In your AndroidManifest.xml you should have something like:
<application
android:icon="#drawable/app_icon"
android:label="#string/nuboLogin"
android:name=".LoginApplication"
android:debuggable="true">
<activity
android:name=".WallPaperActivity"
android:label="#string/wallPaper"
android:windowSoftInputMode="adjustPan"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
This should make sure that your Activity runs in portrait mode. If you prefer landscape, you can easily guess what you should modify
Android application restarts the activity when the orientation changes. You can either use
android:configChanges in your manifest. The activity is shut down and restarted by default, when a configuration change occurs at runtime, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
use android:screenOrientatin = "portrait" or "landscape" it will force the app to run in the mode you specify. However it will not prevent the activity from being shut down and restarted.

App using libgdx restarts whenever device rotates

I made an app using accelerometer but problem is whenever it detects rotation of the screen, it goes to main menu.
I used following code to disable rotation but it still detects the rotation action and goes to mainmenu although it does not become landscape mode anymore.
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
How can I prevent this rotation detection?
Put android:screenOrientation="portrait" inside your activity tag in the AndroidManifest.xml file. That attribute defines that this specific activity should always be run in the portrait mode and thus Android will not try to change screen orientation on rotation.
You will also want to add
android:configChanges="keyboard|keyboardHidden|orientation"
in order to prevent restarts when the keyboard appears or is hidden.
If you use this, you can even remove android:screenOrientation="portrait" if you want your game to work in both landscape and portrait mode. See the libgdx wiki: https://code.google.com/p/libgdx/wiki/ApplicationConfiguration#The_.xml_File
Kimi answer is correct, but if you want to run your game also on the Amazon device, then you should add the additional value "screenSize". So result would be:android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

How to force the screen orientation to portrait before starting an App?

I am using the following line of code for each of my activities in order to force the screen orientation to portrait mode:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
It works ok unless I put the device in landscape mode before launching the app. In this case, the activity closes suddenly.
Any idea on how to manage this case?
you need to use android:screenOrientation = "portrait" in your activity tag.

Android orientation issue

I have application which works only in landscape orientation . I set that in xml layout. When I'm starting application it works ok . But when the application is started and next if I lock the phone and then unlock, the application first 1-2 seconds is in portrait mode and then in landscape. Is it possible to skip theese 2 seconds?
Try defining it explicitly in your manifest. Add android:screenorientation="portrait" to each <activity> element.
Not to be a downer, I really hope you solve this. Just wanted to throw out there that I have noticed this sort of behavior(typically for me the apps are supposed to stay in portrait but they show landscape for about 2 seconds) on multiple applications on my Sprint HTC Hero, including the default home application and many of the default included apps (contacts, etc). I am beginning to suspect it's an android problem. Again, feel free to disagree with me, but I just wanted to say that I have noticed this on a lot of apps & you're not alone here :/ However, there are some apps that I have not noticed it on, so either a) I am just getting lucky or b) there is a correct solution
Execute this in your onCreate(), just before setcontentview:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
I use this method in my apps and I never notice the orientation changing. It's locked solid into the requested orientation.
To be provocative, actually, what he needs to put in each activity element in his manifest is:
android:screenOrientation="landscape"
and not "portrait"
:P
I hope this help; put these on every activity-element in your Android Manifest-file.
android:configChanges="orientation"
android:screenOrientation="landscape"
Of course it is landscape; my brain was not the quickest this time.

Categories

Resources