Making Android app portrait only makes it one-way portrait - android

I've made my app portrait-only and it works successfully, however there seems to be a cache. I can only have this kind of orientation:
[
But I can't rotate it 180°, it just shows like this:
But if I leave the app, the screen rotates. So the problem is, it seems that the app is being set to one-way portrait, is there a way to fix it? Here's how I'm setting portrait-only in each activity:
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
Is there an option to fix this?

Try using this instead...
android:screenOrientation="sensorPortrait"
If this doesn't work let me know!
Edit
So people see this, it only works with API 9+ as #AbAppletic said in the comments below.

Related

Make android app to work in portrait or reverse portrait only

I am working on android app and wish to make this app work only in portrait or reverse portrait mode. In the manifest file I mentioned screen orientation value as "sensorPortrait" but app works only in portrait mode, i.e., if I hold my phone upside down, nothing changes in my app. Although, I do have other apps on my phone that work in both portrait and reverse portrait mode. I have seen similar question asked before but suggestion given don't work as those questions were asked way back and suggestion given might not be a good answer anymore. Any recommendations? Thanks!
You can add in your AndroidManifest.xml file, you need to configure the to use the orientation from the sensor. This should be the default, but you can force it to the sensor's orientations, for all 4 possible orientations, with android:screenOrientation="fullSensor"
<activity android:name=".MainActivity"
android:screenOrientation="fullSensor"/>

Portrait app shows as Landscape

I am an Android developer and have recently made an app for a client. The screen orientation should only be available in portrait, so I have added the option android:screenOrientation="userPortrait" to each and every activity in my manifest.
Despite this, my client keeps telling me that the app displays in landscape on her Samsung Tablet. I don't know why this may be, according with http://developer.android.com/guide/topics/manifest/activity-element.html the orientation should never be landscape. In all of my tests it is displaying correctly (portrait mode), but I don't have access to her device and don't know what is going on.
Any help would be appreciated. Thanks!
You should write this :
android:screenOrientation="portrait"

Why when rotating the phone from portrait into landscape, does the app lose all data?

I'm trying to create an app in Android, using Eclipse ADT and I use a HTC phone. Here's the problem: after running the app on the phone from Eclipse, I add elements to my ListView and everything is fine, BUT when I turn the device in landscape mode the hole app seems like it restart, there's no more records inside. It's like new. Any ideas why and how I can solve this problem? Please don't tell me to deactivate the screen rotate option from phone settings.
This is the way android handles orientation changes. It reloads your whole activity. The normal way to handle this situation is to save the state of your activity in onPause() and then retrieve it back in onCreate().
Here is more information on the android activity lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
EDIT:
You should implement onPause() anyway, because it will also be called if the phone rings in the middle of running your activity. In this case, when the user comes back from the call your activity will possibly be reloaded from scratch again and the user will lose their state.
There is a similar question here.
Basically you application is restarted. You can either force your application to portrait or follow the steps here to find out how to handle it properly.
I made answer over here about this sort of thing.
Please don't tell me to deactivate the screen rotate option from phone settings.
I'm not sure if you meant the following, but here's a solution:
Add android:configChanges="orientation|screenSize" to your <activity tag, which is in your AndroidManifest.xml, like so:
<activity
android:name="activity_name"
android:label="#string/app_name"
android:configChanges="orientation|screenSize" />
This will prevent the activity from being destroyed when the orientation is changed, like it usually would. There are other ways to fix this as well. Please leave a comment if this is not your desired solution. I can make up another.

How can i stop orientation change in android table?

Hi i am developing android application in tablet version. Here i am facing problem with orientation so i want to make my application in portrait mode only. For that i Used attribute like below snippet for each and every activity in my application.
android:configChanges="keyboard|orientation|keyboardHidden"
android:screenOrientation="portrait"
Application is running perfectly while testing in portrait mode. But it is not good while testing application with tablet physical position with landscape. It is first going to landscape then immediately going to portrait.
I used programmatically making the activity in portrait but no effect. Please provide me any help.
Here is my programmatic orientation fix
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I tested in Motorolo device
Please suggest me to avoid my application going to landscape.
Try this...
<activity
android:label="#string/app_name"
android:name="abc.xyz.dd.MainScreen"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
By adding this in manifest file it will prevent from changing to landscape mode.
Finally i find the reason why orientation changes are occurring in android tablet. In ICS (version 4.0+) the tablet have the option like "Don't keep activities" in settings>> Developer tools>>
If the user checked that option the paused activity will killed and created when it is call again. what i mean the activity won't go for onPause() state it will go for onDestroy() and it will created again when press on back key. So the orientation behavior is different.
I did not get the idea how to handle it from our android code

Handling orientation on lockscreen for an android app

Testing my application on my Galaxy S2 I have a problem whenever the screen is turned off and back on. My application is locked into landscape by the manifest. The lock screen forces the application into some weird orientation where it is rendering portrait but displaying it was landscape (as in the right 2/5 of my screen is black and the portrait rendering goes off the bottom). The application is also not responsive in this state. If I quickly hit home (or back) and recall the application it works perfect.
As well, if I use a different lock screen (tried with PowerAmp) it works flawlessly.
So can anyone help me understand why this is screwing up and how to fix the orientation whenever this happens?
I can avoid this by avoiding the lock screen through a flag (window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)) but I don't have any other reason to avoid a lock screen and would like to know what is happening.
This sound like a problem that is unique to the S2. Have you tried your app on the emulator or any other devices. It may just be that the S2 implements some part of android incorrectly.
To handle the orientation problem in your application try to use this for your activity like this
<activity android:configchanges="orientation|keyboardHidden" />
in your Android Manfiest file.

Categories

Resources