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.
Related
I have stumbled on a problem, that, when the screen turns off while being in LANDSCAPE orientation, certain devices "rotate" the app back to PORTRAIT position (because the lockscreen is PORTRAIT only or something like that). I did a little research before posting this, and most popular work-around is to modify app's configuration change process to prevent activity being recreated after the configuration has changed.
But disabling activity recreation is not a solution for me, because my app supports both orientations with sepparate layout's etc.
So i would like to find out, is it possible to disable the configuration change only in special cases (Screen turned off and orientation is landscape)? Or is the right way to override onConfigurationChanged() then manually manage activity recreation inside that function (i guess simply setting different layout resources when orientation is changed simply wont cut it)?
Or is the right way to override onConfigurationChanged() then manually manage activity recreation inside that function?
Yes to an extent.
You cannot set the configChanges attribute programmatically. I guess it's to do with the way an Activity is created. They're created from the XML first and then the overridden methods in your activity implementation are invoked. There's nothing in the API that lets you change the configChanges attribute.
Now in your case it doesn't sound like you need to. If you support both orientations, then if the user locks the device and it rotates back why does it matter? From a UX perspective we know it's in portrait mode again. So should your app when it opens back up.
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.
Is it possible in Android to capture screen rotate events but not actually have the activity respond to the rotate events?
To make things more difficult, I've got an activity backed by a TabActivity, and in one of the tabs I want to rotate some of the content area on screen - but leave the tab in portrait mode.
I've tried setting the activity orientation to portrait in the manifest, but then I no longer get the onConfigurationChanged(..) events. However, If I remove this line, the whole tab rotates as well.
Any help appreciated!
You might want to add "orientation" to activity's configChanges property in AndroidManifest.
android:configChanges="orientation"
http://androidappdocs.appspot.com/guide/topics/manifest/activity-element.html#config
Set the orientation to portrait mode in the manifest as you did, but listen directly to the accelerometer sensor (which is the sensor from which Android derives the orientation of the device) updates and parse them yourself to know when the orientation changed.
It's actually quite easy to do. See here for an example: http://www.anddev.org/accessing_the_accelerometer-t499.html
I have an Activity with a fixed orientation, android:screenOrientation="portrait" in my manifest. I noticed that when pressing Cntl-F11 on the emulator and when a user slides out the keyboard on a device the Activity is destroyed and onCreate is called.
Yet when I use a non-slide out keyboard device the Activity is never destroyed, simply because it is locked to portrait.
Why is there a difference in behavior between devices? Why is an Activity that is locked to portrait, invoking a configuration change? This is really irritating.
Edit: I also experimented with android:configChanges="orientation without any noticeable difference.
You can probably prevent this by telling Android you want to handle the configuration changes yourself via the configChanges attribute.
However, doesn't this point out why it is a bad idea to force the app to be in portrait? That is really annoying on phones with a keyboard.
I'm currently working on an Android application that have different behaviors according to the screen orientation.
I'm using getWindowManager().getDefaultDisplay().getRotation() to get the screen orientation in the onCreate() method and manage from there.
Basically, my problem is that I need a control over the orientation. In landscape mode, when the user decides it, the application must switch to portrait mode, and stays like that, but only until the use goes to portrait mode, and then again to landscape.
I'm using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) to change the orientation when in Landscape. The problem is, using this, I can not go back to landscape.
If I use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) in onCreate(), the problem is that is switches back to landscape mode after a few seconds (since the screen is still in landscape).
Is there any other way to manage this? Basically, is there a way to catch the screen orientation change with a listner (or anywhere else than in onCreate, since it's not called when the views is locked in portrait mode)? I can't find anything about that...
Any idea is welcome!
Thanks!
Why not try creating two layouts, one in layout-land and one in layout-port. These will automatically be applied when the device orientation changes.
Inside each of these, create two distinct child layouts one for a portrait view, and one for a landscape view and change the visibility of these to reflect the user's preference.
So, you don't need to handle the rotation change at all, let Android manage that for you, and you just manage the user override.