Activity orientation is inherited from parent - android

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.

Related

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

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.

Android PreferenceActivity wiered behaviour

In my application Preference Setting Activity is not showing correctly sometimes. It goes black.
My Original Preference Activity
But sometimes it goes black and shows as below screenshot
no check boxes and list preference are visible.
When it goes black and I scroll It looks very poor
The Declaration in Manifest file
<activity
android:name="com.test.wallpaper.PreferenceSettingActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
You have need to set Background for parent layout in this xml page.
Use setbackground for parent layout in xml.

softInputMode in fragments

I have a NavigationDawer with some fragments which contain EditTexts. When I 'open' the fragment, the layout is fine (ie. not squashed) but when I bring the keyboard up, the layout becomes squashed.
I searched around and added this to the manifest:
<activity
android:name=".Navigation_Drawer"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize" > // This being the important part
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Because the Navigation Drawer is the only activity that contains/starts these fragments, the fragment's softInputMode should be controlled by the activity, but this code does not make any difference
Thank you
Remove the code:
android:windowSoftInputMode="adjustResize"
from manifest file.
Have you tried setting the windowSoftInputMode to adjustPan?
adjustResize will resize the activity to allow room for the keyboard, which is the behaviour you are experiencing. If you set the windowSoftInputMode to adjustPan, the activity will be be 'panned', or moved upwards to make room for the keyboard.
android:windowSoftInputMode="adjustPan"

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