Android Parent and Child ActivityOrientation - android

While running a landscape activity and a popup dialog is displayed, which is in a portrait mode, I've noticed that the parent activity was also rotated to portrait mode. Is it not possible to set the orientation of the parent and child activity independently?
EDIT: It is not actually a child activity. I am sorry if I've used wrong terminology. It is actually a different activity/application which is loaded while the 1st activity/application is still running. What I have noticed that it is happening in case of the following settings,
1st activity: android:screenOrientation="landscape"
2nd activity(dialog msg): android:screenOrientation="portrait"
Thanks,
artsylar

You can apply rotation transformations to child views, but you'll have to take over control of portrait landscape yourself entirely. There's no built-in way to do that.

Related

android switch layout on rotate

I have an activity with a videoview and a button, I have two different layout, one for portrait mode and second for landscape.
So, I create layout-land for second layout, and all works fine.
The problem is when rotation occours. Videoview restart becouse Activity renew.
Setting in manifest orientation|screensize video not restart, but I lose landscape layout.
How to do both tasks ?
Keep the configChanges in your AndroidManifest.xml, but also make use of onSaveInstanceState and onRestoreInstanceState to put the activity back in to the state you want it to be in after the orientation has changed.
Look here for more details

Landscape to Portrait recreates activity?

I'm allowing the user to work in both landscape & portrait modes but when I switch between these two modes it just brings the activity to its starting point.
For Example; I enter all the specifications for which I want to view the data in some activity but when I switch the mode from landscape to portrait or portrait to landscape it just brings the activity to its starting point & I've to enter all the specifications again to view my data.
Is there any solution to it or will android always re-create the activity on switching between two modes?
Thanks. :)
This is the expected behavior by default. It is reasonably easy to handle this situation. Basically you save your Activity state (and data), then repopulate your Activity when the screen is rotated (and the Activity is recreated).
Here is a good SO with the solution:
Handle screen rotation without losing data - Android
also worthwhile to read the docs on this subject (and understand the Activity lifecycle in Android):
http://developer.android.com/training/basics/activity-lifecycle/index.html
That happens because on orientation change the activity is destroyed and re-created. A way to avoid this could be by adding the following line inside your activity tag in manifest.xml
android:configChanges="orientation|screenSize"
Example :
<activity
android:name="MyActivity"
android:configChanges="orientation|screenSize">
</activity>

Orientation issue with landscape mode

I am displaying Timer on a screen .
After starting the Timer , I am changing the orientation from the portrait to landscape mode. In order to avoid the timer getting reset when changing from the portrait to landscape mode , I am adding the following code to the activity declaration in the manifest:
android:configChanges="orientation"
The problem I am facing is that , when the screen is switching from the portrait to landscape mode , the layout which gets displayed is same as portrait & not in landscape mode. Only a part of the screen of the landscape orientation is being occupied.
Is there any way by which we can avoid resetting the timer from changing from the portrait to landscape mode & also have a proper landscape layout?
Kindly provide your inputs.
Thanks in advance.
There is a simple way of doing this.
if you have two different layouts for landscape and portrait then let the android handle all the stuff for you. i mean do not override methods onConfigurationChange() method unless strictly required and do not add android:configChanges="orientation". just make different folders for portrait mode and landscape mode. viz. layout and layout-land....
To save present state of views use bundle. whenever orientation changes android reload activity and call onCreate() method. This saved bundle is passed in onCreate() method. Now you can retrieve views' state from this bundle.
now next question will be how to use this bundle. Then here is the quick example.
override onSavedInstanceState() method to save bundle.
Thanks.
Is there any way by which we can avoid
resetting the timer from changing from
the portrait to landscape mode?
Yes, store the value somewhere during onPause and read it during onResume.
Also have a proper landscape layout
Read up on Providing Resources, in particular table 2's "Screen orientation" section which also links to a very nice page about handling runtime changes.
All you need to do is make the manifest file set the screenOrientation="landscape"
<activity android:name=".main"
android:label="#string/app_name"
android:screenOrientation="landscape">
<intent-filter>
That turns off the auto sensor on only the form that you name to have landscape.

android application containing activities with different orientation

I have an activity group say mainActivity which contain 4 activity groups. say one, two, three and four.
All activities except fourth one has orientation portrait. The fourth activity group's orientation varies it may be portrait or landscape.
when i change fourth once orientation from portrait to landscape whole application restarts.
Is it possible to do such kind of things. that mainActivity group has orientation portrait and its child orientation is landscape. And also to allow to change child's orientation without restarting application.
thanks
You could prevent the activity from restarting by adding android:configChanges="orientation" to your activity in AndroidManifest file. But it's generally not advisable to do that as stated in the documentation:
Using this attribute should be avoided
and used only as a last-resort. Please
read Handling Runtime Changes for more
information about how to properly
handle a restart due to a
configuration change.
Source: http://developer.android.com/guide/topics/manifest/activity-element.html#config

Android screen orientation bug

I am using android HTC HERO 2.1 version.
The activity I write :
<activity android:name=".gogogo"
android:label="#string/app_name"
android:theme="#style/Theme.mine"
android:screenOrientation="landscape"
android:configChanges="orientation">
let my orientation change to landscape.
However, I figured out that every time I pressed "power" button and then come back to my activity, it always start at portrait.
I tried the game : TEETER , which was written not by me. Has the same problem too, any one know how to fix it??
Edit: it always start at portrait. --> I mean, if you come back from power, you have to scroll down to do everything, there is something like screen lock.
You can see that there is a "status bar" at the top of the screen and at this time, the orientation is "portrait". So after You scroll the "screen lock" a little bit down, you can see the activity (such as TEETER) is at "portrait" state. When you scroll all the way down, the activity's orientation will suddenly change to the state "landscape".
So the conclusion is : My activity is forced to orient once. And I really want to know how to fix it!
Hai Steven Shih:
Pls go through this page of developer guide.
http://developer.android.com/guide/topics/manifest/activity-element.html
and try this line
android:windowSoftInputMode="stateUnspecified|adjustPan"
Not sure if it's the same problem, but here is the problem I had :
I force the orientation as landscape in the manifest
My activity has a two surfaceviews ( a camera preview and a layer on top of it )
After pressing the power button and coming back, my views were suddenly in the wrong orientation
It seems to be the same problem as another question : Disable orientation but detect orientation
I think the problem is that once you press the power button, the lock screen forces the orientation as portrait. In the onConfigurationChanged I get an orientation change right when I press the power button, which was unexpected because I told to explicitly lock the orientation. The fact is that when another activity which comes in front forces the orientation, the other activities get notified of the orientation change, even if they asked for an explicit orientation.
Here's my workaround :
in onPause, detach the views with removeView ( my application has programmatically created views, not an xml layout )
in onResume , first check if the orientation is the one you requested ( getResources().getConfiguration().orientation ). If it's the case, reattach the views ( addContentView or whatever ).
if the orientation is not the one you expect, call setRequestedOrientation
onConfigurationChanged will be called to tell the orientation has been changed to the one you requested. At this point you can reattach the views with setContentView.
Seems a bit complicated, but that's what I had to go through in my particular case, since my views are created dynamically and directly attach to the default FrameLayout of the activity. Maybe I then missed some default behaviors because of that, but this way I could achieve the reactivity I was looking for.
Not sure whether this can be called a fix, but it's kind of a work-around.
#Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus)
setContentView(mGameView);
else
setContentView(mEmptyView);
}
Where mGameView is your ordinary content and mEmptyView is just a simple View object. The activity will still be drawn in portrait for a frame or two, but it will not be visible to the user.
I've tested this with HTC Hero and Nexus S.

Categories

Resources