The first activity(locked portrait orientation) has 2 buttons that both open the second activity but A button opens it in portrait and B button opens it in landscape orientation.
The problem is that when B button opens the second activity (which is in dialog configuration and the first activity is shown in the background) the first activity changes orientation with the second one, thus restarting.
The question is, A) Can i prevent first activity from changing orientation and B) Can i disable orientation change animation so that the screen doesn't look like turning from portrait to landscape but just becoming landscape instead?
P.S For the A) question i know how to use saved state but i want to avoid it.
Use Below Code in Manifest:
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
Edited:
Sorry there is no way to control the rotation animation. This is done way outside of your app, deep in the window manager where it takes a screenshot of the current screen, resizes and rebuilds the UI behind it, and then runs a built-in animation to transition from the original screenshot to the new rebuilt UI. There is no way to modify this behavior when the screen rotation changes
Related
I've set android:configChanges="orientation|screenSize" on an activity to stop it restarting the activity everytime the orientation changes. Now this works fine but I think it's stopping the correct layouts from being used.
E.G. I have different layout folders for different orientations and sizes of screen. So if I start the activity in portrait, when I change the orientation to landscape, it's not using my landscape layout.
Also if I start the activity in landscape, when I change the orientation to portrait, it's not using my portrait layout.
Basically what I want the app to do is not start the activity again once the orientation changes, but use the correct layout when the orientation is changed!
I was thinking I could use the onConfigurationChanged method to explicitly change the layout in code?
Thanks for any input
when you use android:configChanges="orientation|screenSize" this tells to Android that you will maintain these changes by yourself - this means you have to change your layout (setContentView) and initialize it manually (set values of controls - EditTexts, Spinners etc.)
So What I've ended up doing is keeping android:configChanges="orientation|screenSize" in the manifest file. Doing it this way stops me being able to use my correct layout folders for portrait and landscape.
To overcome this issue, I override the onConfigurationChange method to set the correct information I needed for the activity to run as expected once the orientation changes. below is the code I've used:
#Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
setContentView(R.layout.hearing_test);
//Any other information needed for the activity to work correctly
}
Thanks for the help and guidance #mihail, helped me get to the bottom of the issue.
That is exactly why the Activity is destroyed and recreated: to apply new resources.
Do not use android:configChanges="orientation" if you have different layouts for portrait and landscape mode.
When I click a button in my App, the screen orientation will automatically go to landscape :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
The screen get to landscape successfully but it caused my onConfigurationChanged not working anymore.
I tried to use: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); but it makes no difference.
What should I do, to make the screen go to landscape, when I click the button, without turning off the onConfigurationChanged?Or do you have any other ways to accomplish this?
If you are using API13 or higher as your target,
in your manifest you need to add ScreenSize to your configChanges:
android:configChanges="orientation|screenSize|keyboardHidden"
That should do the trick!
Similar questions have been asked before, but I couldn't find an answer to how to make one element full screen. I would like to temporarily display a full-screen animation in my Android app without moving to a new Activity. The app has an ImageView for the animation and I show the animation with:
image.setBackground(animation);
and make it "go away" with:
image.setBackground(null);
For the ImageView, both android:layout_width and android:layout_height are set to "match_parent". It works, but of course the animation doesn't include the title bar at the top or the icons at the bottom. I even tried setting the layout_marginTop and layout_marginBottom to negative values, but I know that can't be the best solution for every device or orientation which may run this app.
How can I change the size of the ImageView to full screen so I can show it as needed, or is there a better way to do what I want?
Duplicate of Fullscreen Activity in Android?.
Just set the right flags and dismiss the activity when it's finished its animation.
Your ImageView is stuck inside the bounds of your Activity. And I don't think there is a way for you to change your Activity to be full screen sometimes but not others.
If you want your Activity to be fullscreen always you can set the theme in the manifest like this:
<activity
android:name="com.your.package.name.YourActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
Combine both answers. Create a new activity to play your animation and set the theme of your animation activity to fullscreen.
i have already posted my issue in SO and got an answer but i have a problem in that too
my former question is
"i have created a quiz game in my app. The game is to be played in portrait mode. After the game gets over the score is been calculated and its been showed in the score page when i click ok a pop up window appears and asks for the name. I have placed an option to share the result in facebook and twitter.
now when i enter the name and click ok, a page with score name and share button appears, if i click share it moves into facebook or the other, but if i change over to landscape mobe my app gets crashed."
i got a solution to add a line in manifest file
<activity android:name=".main"
android:configChanges="orientation" />
along with the following code in the class file
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
This answer helps me to move to next operation without crashing my app but the problem is when i change from landscape to portrait, the background image and text also gets changed to portrait and half the screen the seems to be a blank one and text or not appearing fully.
this is the same when changed from landscape to orientation. i want the image and text to be fitted to proper orientation.
this problem has not occured before entering those manifest and coding lines
pls give me a solution.
You could try an explicit definition of your layouts.
For example have two layout files, one for landscape and another for portrait. Android is intelligent enough to use the best available layout -> Read HERE
To handle screen orientation gracefully there is something more you need to do -> Read HERE
I have a button which is basically used for start/stop. So initially the text of the button is set to start. I attached a OnClickListener to it. So whenever it gets clicked i change its text. So if it was start it become stop and vice-versa.
The problem comes when i change my phone view from portrait to landscape or vice-versa the button text gets reset.
So for example I clicked the start button---it changed to stop. Now if I tilt my phone to change the view the button text gets set to start again.
Am I using the button in a wrong way?
You should save your button state. When screen orientation changes, onCreate is called and all your app variables are re-intitialized. Read more here http://developer.android.com/reference/android/app/Activity.html
No, you are using the button in the right way.
The thing what you are seeing is "configuration change". When you are tilting your device, Android recreating your activity and recreating all it's views (so, they getting default captions as them described in XML).
You need to do the
disable configuration changes for your Activity. To do so, add the following to your manifest's activity tag: android:configChanges="orientation|keyboardHidden". It is not suitable, if you have different layouts for landscape and portraint orientations, when you need to...
handle the configuration changes by overriding onSaveInsatnceState method of your Activity, save a state there and then use it in onCreate method.
See this article for further explanation