I wish to disable the landscape view in an android application . I've used :
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
It works but there is a slightly big problem . If I rotate the screen the activity restarts , and when it comes back , the screen is still in portrait mode . I want my app to completely ignore the device's position . There is no point in disabling the landscape view if when I rotate the device the activity restarts ( the screen becomes black for a few seconds , and then the activity appears again still in portrait mode ) .
android:configChanges="orientation|keyboardHidden|keyboard"
write a class and extend it to the activity. In that class add this code to a method.
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Then call this method to the activites to which you want to disable the landscape mode..
Related
I have an activity with "portrait" orientation in AndroidManifest.xml.
When I start it from lock screen in landscape orientation, it appear with landscape for 1 second, and then change to portrait. The delay happens even if it's an blank activity (no view, no task).
Tell me how to avoid this delay. Remove transition effect, rotation effect? I know it could be device performance, but still want to fix this.
If you always wants to run your app in landscape mode than use this code in Manifest file for all activity
<activity
android:name=".yourAcitvity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"
/>
That't the default behavior of Android, you can verify this issue using system apps. For ex: open the Android's default messenger, and turn it to landscape and lock the phone, now unlock it and you can see the messenger has re aligned to portrait, that's because the home screen is set to portrait by default. In order to show the home screen the system aligns the device to portrait again.
a while back I converted my app to include landscape mode, from each activity having screenOrientation="portrait" to this:
<activity
android:name="bundle.android.views.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="fullSensor">
I also handle configuration changes just fine in onConfigurationChanged in each activity.
But in hindsight, I only want edge cases with pop out hardware keyboards to get landscape mode. How do I adjust my manifest and code?
do I keep a certain combination android:configChanges ? the onConfigurationChanged class? insight appreciated
One option is to tackle this problem programmatically. What you could do is detect if the user has a hardware keyboard attached, and if so force the orientation into landscape mode. Here are two ways to detect a hardware keyboard:
http://developer.android.com/reference/android/content/res/Configuration.html#keyboard
and
if (getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
}
Once you have detected that the user has a hard keyboard you can force landscape mode on the user with:
myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
I have managed to change the Orientation for my fragment in my activity.
The Orientation is changed when my device is rotated.
Now I want to same functionality when I click on a button in the fragment.
i.e. I want to change from portrait mode to LandScape mode when I click on a button on the portrait layout and visa vera.
I used
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
and
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
respectively.
But this made the auto rotate functionality stop working. How can I fix this issue?
When you need auto rotating use getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Please try this
<activity
android:name="<class name with package>"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait">
I use in the AndroidManifest:
<activity android:name="Zoom" android:text="#string/Name" android:screenOrientation="landscape"></activity>
to force this specific Activity(B) to be been see as landscape, my problem is when i am moving to the next Activity(c) or back to the Activity(A) its still show as landscape
what i should do different??
thanks for helping!!
If your device is in landscape orientation, and you're not specifically setting orientation for the other activities, then they will show in landscape orientation.
Force the other activities to portrait with android:screenOrientation="portrait".
This will mean if your device is in landscape and you switch activity, the new activity will display in portrait (on its side) and the user will then have to rotate the phone into portrait mode to view it correctly
I specified an activity to be portrait-only in menifest file:
<activity android:name="mytest"
android:alwaysRetainTaskState="true"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:screenOrientation="portrait">
But it won't work on Droid when its hard keyboard is popped out.
When hard keyboard is popped out, the device always renders the layout of the activity in landscape orientation first, then it switches it back to portrait orientation. How can I let the app only render the activity in portrait orientation?
Can anyone help? Thanks.
Try using this in your activity description
android:configChanges="keyboardHidden"