Tablets: android:configChanges="orientation|screenSize" and screen disabling issue - android

I have application with screen rotation.
rotating mechanism i handle with configChanges:
<activity
android:name=".ui.activity.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize"
android:screenOrientation="fullSensor"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Problem:
When user turn off screen, rotate device on 90 degrees and unblock it screen start with "old" orientation of my app, it look ugly.
here scheme:
after block and rotate i get this
blink and app come to normal
try it on Nexus 5(android v5) and Nesus 10(android v4.4), at phones all works fine

Adding android:configChanges="orientation|screenSize" tells the system that you are going to handle these config changes yourself, and for the system to not do anything about it.
By removing them, your activity will be recreated with the correct layouts when you rotate.
If you're using configChanges to avoid the activity being recreated, I feel bad for you son.

Related

screenOrientation portrait not always working

I'm making activity which should always remain in one orientation on all devices, preferably portrait.
here is my activity
<activity
android:name="com.example.app.Settings"
android:label="#string/settings_activity_title"
android:autoRemoveFromRecents="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
It works on phone devices but when I tested on virtual tablet it didn't.
I test on Nexus 9 in Android Studio and made my own device with dimensions 2500x2500, screen size 9in.
In such cases, screen will still rotate.
I have also tried setting orientation programmatically inside onCreate method but it didn't help.
I tried to find any information regarding this problem but couldn't.
My question is if this is related to android studio emulator, or this can happen on physical device

Activity orientation is inherited from parent

I have an Android application with 2 activities (actually more, but it doesnt matter here).
The 1st one has fixed orientation (landsape) and the 2nd one has default (undefined) orientation. The 1st activity acts as a splash screen then starts 2nd activity automatically.
The problem is 2nd activity inherits landscape orientation from the 1st one, i.e. if device orientation is vertical when 2nd activity appears it has landscape orientation then immediately rotates to vertical one.
If I remove the 1st activity so that the 2nd one appears during start it doesnt happen.
Note I can neither set vertical orientation for the 1st activity nor set undefined orientation and draw accordingly for some reason.
Please help.
<activity android:name="SplashActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:configChanges="screenSize"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="GameActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize"
android:screenOrientation="fullSensor">
</activity>
I also tried using 'undefined' or not to set any orientation at all for GameActivity.
I hope I got it right. So you want, that the second Activity doesn't get the rotation of the first one.
Use the following inside the onCreate() method in the second Activity:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
If it still doesn't help, then it's just Android's behaviour.
If it helped, it's good.
After the Intent in the first Activity, which should look like this:
Intent intent = new Intent(SplashActivity.this, GameActivity.class);
startActivity(spcthxopen);
You just put
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
under that Intent. I just tried it and it perfectly workarounds Android's default behaviour.

Changing Orientation in Bluestacks to test Orientation Change of my App

Android Emulator 4.4 apparently has a bug which keeps it from changing rotation appropriately. Having heard that Bluestacks is faster anyway, I wanted to give it a shot, but I can't find a way to change my orientation while in my app. My app launches in the full tablet-sized screen of Bluestacks and that's that. The system tray options don't help. I want Bluestacks to look and behave like a standard android phone, with the ability to rotate.
It looks like other versions of Bluestacks have had a rotation button (and other buttons)? I find references to this, but it's not in the latest version I downloaded. Any ideas?
Using the icon on the system tray, setting it to enabled worked for me.
You also have to check if you are forcing the portrait orientation on your manifest. I had to put the tag on every Activity tag, not on the application tag. Like this:
<activity android:name="com.example.LoginActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.MainActivity"
android:screenOrientation="portrait">
</activity>

setRequestedOrientation doesn't lock the orientation

I am trying to lock an activity to landscape mode and have an overlying activity receive and use the orientation changes. The top activity is partly transparent so it is important that the bottom activity locks and is displayed correctly. I have tried to set it programatically with setRequestedOrientation() and in the AndroidManifest.xml with android:screenOrientation="landscape"
When I lock the orientation using the manifest the top activity also locks. When I add android:configChanges="orientation|screenSize|keyboardHidden" the top activity changes orientation but so does the bottom activity. Sometimes the bottom activity goes completely blank (transparent) after the orientation changes.
This is in my AndroidManifest.xml:
<application
android:debuggable="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TopActivity"
android:screenOrientation="sensor"
android:configChanges="orientation|screenSize|keyboardHidden"
android:theme="#style/Theme.Transparent">
</activity>
</application>
MainActivity is the bottom activity. How do I properly handle the orientation changes so that the single activities are locked the way I set them to?
just add screenOrientation to the activity which you don't want to rotate on orientation change in the manifest file like this:
<activity android:name=".Activity"
android:screenOrientation="portrait" />
All other activities will automatically rotate on orientation change.
No need to give screenOrientation for other activities.
1) To disable orientation (i.e. to prevent Android from restarting your activity if the user flips the phone), then specify "configChanges" in your AndroidManifest (like you're already doing, apparently), and then simply don't respond to any changes:
<activity android:name="MainActivity" android:configChanges="keyboardHidden|orientation|screenSize">
2) Alternatively, let's say you want to force your app to "landscape" mode. Instead of "configChanges", you can specify "screenOrientation"
<activity android:screenOrientation="landscape" ... >
3) Finally, if you want to handle the orientation change, you'll need to a) save state, then b) do whatever processing you need (including, perhaps, notify other activities):
http://developer.android.com/guide/topics/resources/runtime-changes.html

Orientation Changes distorted the View in Android device

My app is done in Titanium. I am struggling with a issue which is that when I= launch the App by keeping the device in landscape mode. Then while loading Splash screen it first goest in Landscape mode and when app finally launches Whole UI got distorted by that orientation change. I have added the below line of code in TiApp.xml
<application android:screenOrientation="portrait" android:configChanges="keyboardHidden"/>
even though its rotating. I want to stop the orientation change of that splash screen while launching. Any idea?
In each activity you have to write
<activity android:name=".MainActivity" android:configChanges="keyboardHidden|orientation" android:screenOrientation="landscape" />
Hope it help!!
Try this. Add you custom androidManifest.xml For custom xml
and add this line in androidManifest.xml and run I think this is very useful for you.
<activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/>
<activity android:configChanges="keyboardHidden" android:name="ti.modules.titanium.ui.TiTabActivity" android:screenOrientation="portrait"/>
Cheers

Categories

Resources