I observed one problem in status bar that while we open it from the home screen and change the device to landscape mode, the orientation of the status bar is not changed to landscape,
but if we open any applications like messaging in which their orientation is changed according to device orientation and then open the status bar, it will also change the orientation.
That means keeping an application who orientation is constant in background and then opening the status bar will have this problem that orientation of status bar also becomes constant.
Please give me some suggestions so that I can rectify this problem. If I could know that who is parsing the xml file and if android:configChanges="keyboardHidden|orientation" is present in the manifest file who is deciding not to send Intent.ACTION_CONFIGURATION_CHANGED
you should prepaire to create landscape layout also.
for landscape mode-> layout-land
for portrait mode-> layout
android:configChanges="keyboardHidden|orientation" , this tag used when we dont want to change state in our activity when orientation is changed
if android:configChanges="keyboardHidden|orientation" is present in the manifest file then our activity will handle itself one or more configuration changes that we specify and need not to handle by android system.That means when we use android:configChanges="keyboardHidden|orientation" we tell android system that our activity itself controll this configuration change.
Related
I have created an app which have a help screen(designed in a separate layout file) open by the 3-dots icon. When I open it portrait mode by pressing 3-dots menu icon the android selects the portrait layout file but when I changes the device's orientation the android still loads the portrait layout file.It is not loading the landscape layout.Although I have created the landscape layout file with qualifiers as sw320-land and portrait layout as sw320. Someone please help me out with this issue.Thanks
1- Check in your manifest if you setted android:screenOrientation="portrait" on this activity and remove it
2- If you don't care about screen size put all your landscape layouts into layout-land
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.
I have a MainActivity.java which has 2 fragments:
1) Fragment1.java -> Has a RecyclerView of items.
2) Fragment2.java -> Displays the details of the item when it is clicked.
In Portrait orientation only Fragment1.java or if item clicked then Fragment2.java is visible.
In Landscape mode both the fragments are visible side by side.
This works fine in both Portrait and Landscape orientations if I start the app in that orientation.
However if I change the orientation in between when the app is still running, then I get the error IllegalStateException : Cannot perform this action after onSaveInstanceState whenever another list item is clicked. The action on which it throws the error is transaction.commit().
Any idea how I can fix this?
I would suggest seeing if you have set the Orientation mode in the activity tag in the manifest and if you did remove it.Android handles this automatically.
such as :
<activity
android:name=".MyActivity"
android:screenOrientation="portrait" />
Regarding the different looks of the fragments when the app is in Landscape or Portrait , this has to do with the Layout you choose in the xml file.
Relative , Linear etc. Please checkout the Android official documentation and use that meets your needs.
I decided to develop my own camera activity since I need to force the user to take a 1:1 ratio picture; just like Instagram. I created my activity based on this activity from an open-source project:
https://github.com/pocorall/scaloid-apidemos/blob/master/src/main/java/com/example/android/apis/graphics/CameraPreview.java
Now I'm trying to handle the screen rotation to avoid the layout from being rotated. In other words, I want to keep the layout from rotating and rotate only the buttons and the status bar depending on the device rotation.
I already declared my activity to listen for config changes in the manifest file.
<activity
android:name=".activity.CameraActivity"
android:configChanges="orientation|screenSize"
android:theme="#style/Theme.Eyes.NoActionBar"
android:windowSoftInputMode="adjustNothing|stateHidden">
</activity>
Stop rotation of layout
Add android:screenOrientation="portrait" into manifest
Detect rotation for individual buttons
Call Display.getRotation() to check how much the screen has roated and adjust buttons accordingly
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);